我有 onclicklistener 可以工作。我正在尝试通过单击列表视图上的按钮启动一个新片段。目前,该片段尚未启动。但是,我们使用的模拟器不会崩溃,因此如果我们正确理解这一点,它就不会连接到新的片段/XML 页面。
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l)
{
myBadData.setId(i);
Fragment fr = new event_description();
//fr.setArguments(bundle);
FragmentManager fm = getFragmentManager();
FragmentTransaction fragmentTransaction = fm.beginTransaction();
//int contId = v.getId();
fragmentTransaction.add(R.id.page, fr);
// fragmentTransaction.add(view.getId(), fr);
// fragmentTransaction.commit();
Intent intent =new Intent(eventList.this, fr.getClass());
}
下面是我们尝试在其上添加片段的视图的 XML 代码。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/page"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.alex.qtapandroid.ui.fragments.DayFragment">
<!-- TODO: Update blank fragment layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<ListView
android:id="@+id/dayList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
改变这一行
Intent intent =new Intent(eventList.this, fr.getClass());
to:
fragmentTransaction.commit;
并更好地替换容器中的片段,
fragmentTransaction.replace(R.id.page, fr);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)