0

我很难将我的活动放在标签中。我有一个解析 XML 文件并将它们放在一个列表中的活动,它可以独立运行。当我在选项卡上调用它时它不起作用(我得到可怕的“对不起!等等等等……已意外停止”提示......顺便说一句,是的,我做了清单)。

我已将活动迁移为一项活动,瞧!有效!!!然而,这不是我们想要进行这个项目的方式——我们真的需要有单独的活动。

所以很多人发现选项卡和活动不能很好地协同工作,有没有办法解决它?可能是某种乳化剂?

这是代码:

导入android.app.Activity;导入android.content.Intent;导入android.os.Bundle;导入 android.widget.TabHost;导入 android.widget.Toast;

公共类 TabDemo 扩展 Activity{

/** data members go here*/

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    try {
        TabHost tabs= (TabHost)findViewById(R.id.tabhost);

        tabs.setup();
        Intent callResultHits = new Intent(this, my.tabebd.layout.ResultHits.class);

        TabHost.TabSpec spec = tabs.newTabSpec("tag1");
        spec.setContent(callResultHits);
        spec.setIndicator("Result",   getResources().getDrawable(R.drawable.ic_tab_search_result) );
        tabs.addTab(spec);

        spec = tabs.newTabSpec("tag2");
        spec.setContent(R.id.tab2);
        spec.setIndicator("Details",getResources().
                             getDrawable(R.drawable.ic_tab_details));
        tabs.addTab(spec);

        tabs.setCurrentTabByTag("tag1");
    } catch (Throwable t) {
        // TODO Auto-generated catch block
        Toast.makeText(this, "Exception: " + t.toString(), 50000).show();
    }
}

这是其中一项活动...

public class ResultHits extends Activity implements OnItemClickListener {
ListView listView_titles;
ArrayList<String> items = new ArrayList<String>();
String [] test = {"1", "2","3"};

    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);



    listView_titles = (ListView)findViewById(R.id.list);

    listView_titles.setAdapter(new ArrayAdapter<String>
    (this,R.layout.row, R.id.row_text,test));


}

}

我省略了 xml 解析部分......如果这个基本列表可以显示在选项卡内,那么它将是完美的。提前TY

顺便说一句,setcurrenttabByTag 以前是 setCurrenttab(2)..实际上我做了这些值 0,1,2,3 以防万一;)

4

1 回答 1

0

发布您的代码我认为将活动放入每个选项卡中不会有问题,这是如何将活动放入选项卡的基本示例,

    static  TabHost tabHost;

...
...
...

            tabHost = getTabHost();  // The activity TabHost
           TabHost.TabSpec spec;  // Resusable TabSpec for each tab
           Intent intent;  // Reusable Intent for each tab
           // Create an Intent to launch an Activity for the tab (to be reused)
           intent = new Intent().setClass(this, MainActivity.class);
           // Initialize a TabSpec for each tab and add it to the TabHost
           spec = tabHost.newTabSpec("MainActivity")     
             .setIndicator(null, null)
               .setContent(intent);
           tabHost.addTab(spec);

           // Do the same for the other tabs
           intent = new Intent().setClass(this, SecondActivity.class);
           spec = tabHost.newTabSpec("SecondActivity")         
           .setIndicator(null, null)               
           tabHost.addTab(spec);

           intent = new Intent().setClass(this, ThirdActivity.class);
           spec = tabHost.newTabSpec("ThirdActivity")
               .setIndicator(null, null)
               .setContent(intent);
           tabHost.addTab(spec);

           intent = new Intent().setClass(this, FourthActivity.class);
           spec = tabHost.newTabSpec("FourthActivity")
               .setIndicator(null, null)
               .setContent(intent);
           tabHost.addTab(spec);
于 2010-07-30T22:55:18.277 回答