我正在
11-13 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.makemyday/com.example.makemyday.ActionDetailActivity}:java.lang.IllegalArgumentException: No view found for id 0x7f050007 (com.example.makemyday:id/action_detail_container) for fragment ActionDetailFragment{41e9add8 #0 id=0x7f050007}
action_detail_activity代码
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_action_detail);
if (savedInstanceState == null) {
Bundle arguments = new Bundle();
String id= getIntent().getStringExtra(ActionDetailFragment.ARG_ITEM_ID);
arguments.putString(ActionDetailFragment.ARG_ITEM_ID, id);
ActionDetailFragment fragment = new ActionDetailFragment();
fragment.setArguments(arguments);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.action_detail_container, fragment);
SupportMapFragment mapFragment;
ImageFragment imageFragment;
Toast.makeText(this, ActionDetailFragment.ARG_ITEM_ID, Toast.LENGTH_SHORT).show();
if(id.equalsIgnoreCase("1"))
{
Toast.makeText(this, "here1", Toast.LENGTH_SHORT).show();
//mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
//map=mapFragment.getMap();
}
else if(id.equalsIgnoreCase("2"))
{
Toast.makeText(this, "here2", Toast.LENGTH_SHORT).show();
//imageFragment = (ImageFragment) getSupportFragmentManager().findFragmentById(R.id.picture_upload);
imageFragment=new ImageFragment();
ft.add(R.id.imageContainer, imageFragment);
}
ft.commit();
}
}
activity_action_detail.xml的代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+android:id/outer_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame">
<FrameLayout
android:id="@+android:id/action_detail_container"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<FrameLayout
android:id="@+android:id/imageContainer"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="@+id/start_time_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="from" />
</LinearLayout>
请有人回答此问题
答案 0 :(得分:2)
试试这个..
无需仅使用@+android:id
进行framelayout
fragement listview需要@+android:id
for linearlayout也使用
android:id="@+id/outer_container"
和
<FrameLayout
android:id="@+id/action_detail_container"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/imageContainer"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
修改强>
@+android:id
表示您指的是android命名空间中定义的FrameLayout
。 @+id
为视图定义了自己的Id
。
答案 1 :(得分:0)
非常好..这也救了我.. 机器人:ID =&#34; @ + ID /容器&#34;
我的代码中缺少。