好的,所以在基本层面上,我试图简单地用一系列列表制作一系列列表。主/流起始模板做得很好,除了我想在到达最终内容之前再多“一层”列表。因此,如果您知道更好的方法,请随时提出建议。
话虽如此,这是我的实现。我以master/flow模板开始,并尝试将fragment_detail xml(在我的例子中称为fragment_game_detail.xml)从TextView更改为RelativeLayout,这种更改似乎是在抛出IAE。
作为参考,这是我理解的调用堆栈。
public void onItemSelected(String id) {
if (mTwoPane) {
// In two-pane mode, show the detail view in this activity by
// adding or replacing the detail fragment using a
// fragment transaction.
Bundle arguments = new Bundle();
arguments.putString(RiskDetailFragment.ARG_ITEM_ID, id);
RiskDetailFragment fragment = new RiskDetailFragment();
fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction()
.replace(R.id.game_detail_container,
fragment)
.commit();
} else {
// In single-pane mode, simply start the detail activity
// for the selected item ID.
Intent detailIntent = new Intent(this, RiskDetailActivity.class);
detailIntent.putExtra(RiskDetailFragment.ARG_ITEM_ID, id);
startActivity(detailIntent);
}
}
哪个电话
public void onItemSelected(String id) {
if (mTwoPane) {
// In two-pane mode, show the detail view in this activity by
// adding or replacing the detail fragment using a
// fragment transaction.
Bundle arguments = new Bundle();
arguments.putString(RiskDetailFragment.ARG_ITEM_ID, id);
RiskDetailFragment fragment = new RiskDetailFragment();
fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction()
.replace(R.id.game_detail_container,
fragment)
.commit();
} else {
// In single-pane mode, simply start the detail activity
// for the selected item ID.
Intent detailIntent = new Intent(this, RiskDetailActivity.class);
detailIntent.putExtra(RiskDetailFragment.ARG_ITEM_ID, id);
startActivity(detailIntent);
}
}
Fragment_game_detail 更改为
<RelativeLayout android:id="@+id/game_detail"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".RiskDetailFragment" >
</RelativeLayout>
为什么单击相应的项目会为 id/game_detail_container 引发 IAE?我已经经历了十几个其他关于堆栈溢出的问题,但我发现它们都与我无关。
这是包含该 ID 的 activity_game_detail.xml,但我没有更改它,因为它指向了正确的类。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/game_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".RiskDetailActivity"
tools:ignore="MergeRootFrame" />
在 ListFragment 中,这也可能是问题的一部分:
public void onListItemClick(ListView listView,
View view,
int position,
long id) {
super.onListItemClick(listView, view, position, id);
switch(position){
case 0:
RiskDetailFragment fragment = new RiskDetailFragment();
getChildFragmentManager().beginTransaction()
.replace(R.id.game_detail_container,
fragment)
.commit();
break;
case 1:
break;
default:
break;
}
}