मुझे टुकड़े के अंदर टुकड़े पर काम करने के बारे में मदद चाहिए, वास्तव में मैं बैक बटन दबाकर एक समस्या का सामना कर रहा हूं। आवेदन मुख्य स्क्रीन में प्रत्येक बटन दृश्य पर नए खंड (और उस टुकड़े को किसी अन्य टुकड़े के अंदर शामिल किया गया है) के साथ प्रति बटन दृश्य पर दबाकर दबाया जाता है, गतिशील रूप से जोड़ना/प्रतिस्थापित करना बटन 1 खंड को दबाकर ठीक काम कर रहा है, बटन दबाते समय ऐसा ही होता है, ,टुकड़े टुकड़े के अंदर टुकड़े
"Duplicate id 0x7f05000a, tag null, or parent id 0x7f050009 with
another fragment for com........ fragmentname"
का मतलब टुकड़ा या भीतरी टुकड़े पहले से ही जोड़ रहे हैं और मैं उन्हें फिर से जोड़ने के लिए कोशिश कर रहा हूँ किसी को भी विचार कैसे टुकड़ा अंदर और टुकड़ा के साथ काम करने होते हैं: लेकिन अगर मैं बटन दबाएं, एक अपवाद मिला बिना किसी समस्या के पीछे और आगे बढ़ना,के लिए धन्यवादसमर्थन।
मुख्य गतिविधि, जहां टुकड़े गतिशील जोड़े गए हैं और प्रतिस्थापित किया गया है। main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button android:layout_width="wrap_content"
android:id="@+id/button1"
android:layout_height="wrap_content"
android:text="Button1"></Button>
<Button android:text="Button2"
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
<Button android:text="Button3"
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
<Button android:text="Button4"
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"></LinearLayout>
</LinearLayout>
आशा मैं मेरी समस्या स्पष्ट करने की कोशिश की:
public class FragmentInsideFragmentTestActivity extends Activity {
private Button button1;
private Button button2;
private Button button3;
private Button button4;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button1 =(Button) this.findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
onButtonClick(view);
}
});
button2 =(Button) this.findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
onButtonClick(view);
}
});
button3 =(Button) this.findViewById(R.id.button3);
button3.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
onButtonClick(view);
}
});
button4 =(Button) this.findViewById(R.id.button4);
button4.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
onButtonClick(view);
}
});
}
public void onButtonClick(View v) {
Fragment fg;
switch (v.getId()) {
case R.id.button1:
fg=FirstFragment.newInstance();
replaceFragment(fg);
break;
case R.id.button2:
fg=SecondFragment.newInstance();
replaceFragment(fg);
break;
case R.id.button3:
fg=FirstFragment.newInstance();
replaceFragment(fg);
break;
case R.id.button4:
fg=SecondFragment.newInstance();
replaceFragment(fg);
break;
}
}
private void replaceFragment(Fragment newFragment) {
FragmentTransaction trasection =
getFragmentManager().beginTransaction();
if(!newFragment.isAdded()){
try{
//FragmentTransaction trasection =
getFragmentManager().beginTransaction();
trasection.replace(R.id.linearLayout2, newFragment);
trasection.addToBackStack(null);
trasection.commit();
}catch (Exception e) {
// TODO: handle exception
//AppConstants.printLog(e.getMessage());
}
}else
trasection.show(newFragment);
}
}
यहाँ लेआउट है।
कोड से ऊपर एंड्रॉइड 3 के साथ मेरे लिए बिल्कुल ठीक काम कर रहा है।1 – Vivek
अधिक जानकारी के लिए [Fragments के भीतर टुकड़े] के संभावित डुप्लिकेट (http://stackoverflow.com/questions/6847460/fragments-within-fragments) – Vladimir
देखें http://stackoverflow.com/a/11020531/1219456 –