0

我真的不知道如何解决这个问题,我找到了很多解决方案,但它仍然不起作用。

我的问题是在我的活动跳转到 TabHost 后,标签页浏览变成空白,但是当我切换标签时,它变成了正常。

我猜活动第一次跳转时日期已经准备好了,但为什么它不显示正常?

任何帮助将非常感激..

这是跳转 TabHost 所在的活动。

public class ListContainActivity extends FragmentActivity{

    public static final String tag = "COOLSMILE_DEBUG";
    private  TabHost tabHost ;
    ContextTask contextTask ;
    String mString="";

    @Override
    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 InitUI(){
        getIntentExtra();
        Log.v(tag, "----------- InitUI start -----------");
        InitTabHost();
    }

    private void InitTabHost(){

        Log.v(tag, "----------- InitTabHost start -----------");
        TabHost.TabSpec spec;  

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

        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);  

        InitClickListener();
    }
    private void ProgressRefresh(){        

        Log.v(tag, "----------- progress_refresh start -----------");
        contextTask = new ContextTask(0);

        TaskHost taskHost = new TaskHost(){

            @Override
            public void onPreExecute(int requestCode) {
                // TODO Auto-generated method stub
                super.onPreExecute(requestCode);
                Log.v(tag, "----------- progress_refresh.onPreExecute() start -----------");
                InitUI();
            }

            @Override
            public void onPostExecute(int requestCode, String result) {
                // TODO Auto-generated method stub
                super.onPostExecute(requestCode, result);

                Log.v(tag, "----------- progress_refresh.onPostExecute() start -----------"+result);

                TextView txt = (TextView)findViewById(R.id.text_Result);
                txt.setText("DoInBackground Result :"+result);
                TextView txt1 = (TextView)findViewById(R.id.text_Refresh);
                txt1.setText("Hello my name is "+mString);
            }
        };
        contextTask.setTaskHost(taskHost);
        contextTask.setProgress(new SimpleDialogProgress(this,"正在获取数据..."));
        contextTask.execute();        
    }

    private void InitClickListener(){

        Log.v(tag, "----------- InitClickListener start -----------");

        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();
        mString = intent.getExtras().getString("PRESIDENTS_CONTENT");
    }

}
4

1 回答 1

0

我找到了原因,因为TagsetContent(R.id.contain_tab1)不是一对一的关系。我以为只是设置了一次,现在我已经解决了这个问题。

于 2012-11-12T05:11:10.743 回答