【发布时间】:2017-09-27 10:06:08
【问题描述】:
我正在尝试从 listActivity 的对话框中选择项目后更改当前片段
这是我的 listActivity.cs 类:
[Activity( Theme = "@android:style/Theme.Dialog" , Label ="Number list") ]
class NumberListActivity : ListActivity
{
string[] data;
ArrayAdapter adapter;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
this.data = Intent.GetStringArrayExtra("list_numbers");
adapter = new ArrayAdapter(this, Resource.Layout.specific_contact_number_list_layout, data);
ListAdapter = adapter;
}
protected override void OnListItemClick(ListView l, View v, int position, long id)
{
base.OnListItemClick(l, v, position, id);
//Intent callFragment = new Intent(this, typeof(barMenu));
//callFragment.PutExtra("callNumber", data[position]);
//StartActivity(callFragment);
ISharedPreferences preferences = GetSharedPreferences(SignInActivity.userSessionPref, FileCreationMode.Private);
String UserNamevalueSession = preferences.GetString("UserNamevalue", "");
String UserphonevalueSession = preferences.GetString("Userphonevalue", "");
CallService.phone.Connect(data[position], UserphonevalueSession);
DateTime now = DateTime.Now;
SqliteDB db = new SqliteDB();
db.Insert(data[position], now.ToString());
var frag = new MainActivity();
FragmentManager.BeginTransaction().Replace(Resource.Id.conent_fragment, frag).Commit();
Finish();
}
}
这里的一切都很好,我只需要在点击项目后更改片段
我试过了
var frag = new MainActivity();
FragmentManager.BeginTransaction().Replace(Resource.Id.conent_fragment, frag).Commit();
但它给了我
09-27 12:57:00.247 E/AndroidRuntime(11446): java.lang.IllegalArgumentException:未找到 id 0x7f080079 的视图 (TurkeyanaCall.TurkeyanaCall:id/conent_fragment) 用于片段 MainActivity{4b067018 #0 id=0x7f080079}
我的 specific_contact_number_list_layout.xmal 代码
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/number_list"
android:textColor="#37c837"
android:textSize="20dip"
android:textStyle="italic"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft ="20dp"
android:padding ="10dp"
/>
这是包含我想要更改其命名为 bar_menu.xmal
的片段的布局<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:id="@+id/maintActivity_drawerlayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/linearView">
<fragment
class="TwilioClientTest.Android.MainMenuFragment"
android:id="@+id/conent_fragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/maintActivity_navigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@drawable/shadow"
app:menu="@menu/left_menus"
app:theme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.v4.widget.DrawerLayout>
【问题讨论】:
-
能否把
NumberListActivity的详细代码和xaml代码贴出来?以便我们知道您要更改哪个片段? -
我添加了我的 xaml 页面布局代码
-
我正在从 android.support.v4.widget.DrawerLayout 更改片段,它运行良好,但我的应用程序中有电话簿,我希望当点击联系人姓名时我希望它呼叫联系人并转到我现在可以调用的调用片段,因为它使用服务进行调用,但我想在调用期间更改片段
标签: c# android visual-studio android-fragments xamarin