Сначала вызвать removeView() для родительского элемента дочернего элемента??

#java #android #view #android-fragmentactivity #fragment-tab-host

#java #Android #Вид #android-fragmentactivity #фрагмент-вкладка-хост

Вопрос:

 @ Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bottom_tabs);

    ActionBar actionBar = getActionBar();

    // set the Icon
    actionBar.setIcon(R.drawable.ic_launcher);

    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup(this , getSupportFragmentManager() , R.id.realtabcontent);

    tabIndicator1 = LayoutInflater.from(this).inflate(R.layout.apptheme_tab_indicator_holo , mTabHost.getTabWidget() , false);
    title = (TextView) tabIndicator1.findViewById(android.R.id.title);
    title.setText("Infos");

    tabIndicator2 = LayoutInflater.from(this).inflate(R.layout.apptheme_tab_indicator_holo , mTabHost.getTabWidget() , false);
    title = (TextView) tabIndicator2.findViewById(android.R.id.title);
    title.setText("Info");

    tabIndicator3 = LayoutInflater.from(this).inflate(R.layout.apptheme_tab_indicator_holo , mTabHost.getTabWidget() , false);
    title = (TextView) tabIndicator3.findViewById(android.R.id.title);
    title.setText("Development");

    tabIndicator4 = LayoutInflater.from(this).inflate(R.layout.apptheme_tab_indicator_holo , mTabHost.getTabWidget() , false);
    title = (TextView) tabIndicator4.findViewById(android.R.id.title);
    title.setText("Charging");

    mTabHost.addTab(mTabHost.newTabSpec("infos").setIndicator(tabIndicator1) , InformationTabs.class , null);
    mTabHost.addTab(mTabHost.newTabSpec("info").setIndicator(tabIndicator2) , InfoFragment.class , null);
    mTabHost.addTab(mTabHost.newTabSpec("development").setIndicator(tabIndicator3) , DevelopmentTab.class , null);
    mTabHost.addTab(mTabHost.newTabSpec("charging").setIndicator(tabIndicator3) , ChargingTab.class , null);
  

}

LogCat сообщает, что у указанного дочернего элемента уже есть родительский элемент. и я должен сначала вызвать removeView() для родительского элемента дочернего элемента…

Я просто не понимаю ?!

Я знаю, что проблема в том, что я использую здесь 2 макета, но как я могу ее решить….

Спасибо за любые подсказки

Комментарии:

1. Можете ли вы сказать нам, о каком представлении вы говорите?

2. вы вызываете setIndicator(tabIndicator3) дважды, tabindicator3 не может иметь двух родителей

3. табиндикаторы1, Табиндикаторы2, табиндикаторы3, Табиндикаторы4 частного просмотра;

4. ха-ха! Хорошо, мне потребовалось около 2 часов …… большое спасибо: P

Ответ №1:

Такого рода ошибка возникает, когда вы пытаетесь добавить представление к родительскому элементу, а оно уже было добавлено к другому.

Вы добавляете tabIndicator3 два раза. Замените этот код:

 mTabHost.addTab(mTabHost.newTabSpec("charging").setIndicator(tabIndicator3) , ChargingTab.class , null);
  

этим:

 mTabHost.addTab(mTabHost.newTabSpec("charging").setIndicator(tabIndicator4) , ChargingTab.class , null);