程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> feagment-跳轉到新的ACTIVITY,tabhost當前選項卡顯示為空

feagment-跳轉到新的ACTIVITY,tabhost當前選項卡顯示為空

編輯:編程綜合問答
跳轉到新的ACTIVITY,tabhost當前選項卡顯示為空

跳轉到新的ACTIVITY,新的Activity采用的是FRAGMENT+TABHOST,跳轉後當前的tabcontent內容為空,但是在新的Activity選項卡切換下,tabcontent的內容就又能顯示了!!

問題就是跳轉後,首次的tabcontent不顯示!大家有誰遇到過這樣的問題嗎?
補充下code:

**前一個Activity, R.id.fragment_tab1 是用的Listfragment**

tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();

tabHost.addTab(
    tabHost.newTabSpec(main_home)
        .setIndicator(main_home)
        .setContent(R.id.fragment_tab1)
); 
tabHost.setCurrentTab(0); 
------------------------------------------------------------------------
R.id.fragment_tab1  裡的setOnItemClickListener()方法,是將當前list的item項放在通過intent傳遞到 ,需要啟動的新的Activity中/
------------------------------------------------------------------------
protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE); 

        setContentView(R.layout.showcontain);

        ProgressRefresh();


    }


    private void ProgressRefresh(){

            contextTask = new ContextTask(0);

            TaskHost taskHost = new TaskHost(){

                @Override
                public void onPreExecute(int requestCode) {
                    // TODO Auto-generated method stub
                    super.onPreExecute(requestCode);
                }

            };
            contextTask.setTaskHost(taskHost);
            contextTask.setProgress(new SimpleDialogProgress(this, "加載LIST", "正在加載中..."));
                     InitUI();
            contextTask.execute();      
        }



    private void InitUI(){

            getIntentExtra();


            TextView txt = (TextView)findViewById(R.id.text_cjq);
            txt.setText(texts);

            InitTabHost(); 

         InitClickListener();   
    }


    private void InitTabHost(){

         TabHost.TabSpec spec;  

         //tabHost = getTabHost();

         tabHost = (TabHost) findViewById(android.R.id.tabhost);
         tabHost.setup();
         //    .............

            spec=tabHost.newTabSpec("Refresh").setIndicator("Refresh").setContent(R.id.tab0);
            tabHost.addTab(spec);  

            spec=tabHost.newTabSpec("Love").setIndicator("Love").setContent(R.id.tab1);  
            tabHost.addTab(spec);  

            spec=tabHost.newTabSpec("Comment").setIndicator("Comment").setContent(R.id.tab2);  
            tabHost.addTab(spec);  

            spec=tabHost.newTabSpec("Onward").setIndicator("Onward").setContent(R.id.tab2);  
            tabHost.addTab(spec);  

            spec=tabHost.newTabSpec("Goback").setIndicator("Goback").setContent(R.id.tab1); 
            tabHost.addTab(spec);  

            tabHost.setCurrentTab(0); 

    }

        private void InitClickListener(){

            RadioGroup radioGroup=(RadioGroup) this.findViewById(R.id.main_tab);  
            radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {  

                @Override  
                public void onCheckedChanged(RadioGroup group, int checkedId) {  
                    // TODO Auto-generated method stub  
                    switch (checkedId) {  
                    case R.id.main_tab_addHome:
                        tabHost.setCurrentTabByTag("Refresh");  
                        break;
                    case R.id.main_tab_addExam:  
                        tabHost.setCurrentTabByTag("Love");  
                        break;  
                    case R.id.main_tab_myExam:  
                        tabHost.setCurrentTabByTag("Comment");  
                        break;  
                    case R.id.main_tab_message: 
                        tabHost.setCurrentTabByTag("Onward");  
                        break;  
                    case R.id.main_tab_settings:
                        tabHost.setCurrentTabByTag("Goback");  
                        break;  
                    default:  
                        tabHost.setCurrentTabByTag("Refresh");  
                        break;  
                    }  
                }  
            });     

        }

        private void getIntentExtra(){

            Intent intent = getIntent();

            title = intent.getExtras().getString("title");
            texts = intent.getExtras().getString("texts");
            resID = intent.getExtras().getInt("resIds");
        }

最佳回答:


spec=tabHost.newTabSpec("Refresh").setIndicator("Refresh").setContent(R.id.contain_tab0);
tabHost.addTab(spec);  

spec=tabHost.newTabSpec("Love").setIndicator("Love").setContent(R.id.contain_tab1);  
tabHost.addTab(spec);  

spec=tabHost.newTabSpec("Comment").setIndicator("Comment").setContent(R.id.contain_tab2);  
tabHost.addTab(spec);  

spec=tabHost.newTabSpec("Onward").setIndicator("Onward").setContent(R.id.contain_tab0);  
tabHost.addTab(spec);  

spec=tabHost.newTabSpec("Goback").setIndicator("Goback").setContent(R.id.contain_tab1); 
tabHost.addTab(spec);  

問題就出現在這串代碼裡, 裡面的TAG 與 setContent(R.id.contain_tab1);
不是一一對應的關系 , 原以為只要TAG值唯一就行了!..犯錯了!!
之前為了圖方便, 只在XML裡寫了3個tab 復用了2個tab用來測試,結果調了1天 ,,我靠靠靠靠靠,太悲劇了!!

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved