我的活动结果证明是错的

时间:2012-11-02 07:19:18

标签: android

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

我的问题是在我的活动跳转到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");
    }

}

1 个答案:

答案 0 :(得分:0)

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