无法将片段添加到片段事务处理中

时间:2014-03-03 08:18:20

标签: android android-fragments

这是国家/地区详细信息活动

public class CountryDetailsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.country_details_activity_layout);

    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransacton = fragmentManager.beginTransaction();
    MyFragmentDetails detailsFragment = new MyFragmentDetails();
    Bundle b = new Bundle();
    b.putInt("position", getIntent().getIntExtra("position", 0));
    detailsFragment.setArguments(b);
    fragmentTransacton.add(R.id.country_details_fragment_container, detailsFragment);   <--------error is shown here.   
    fragmentTransacton.commit();    
}
}

这是上述活动的xml文件。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" 
android:id="@+id/country_details_fragment_container"    
>
</LinearLayout>

0 个答案:

没有答案