0

私は自分の活動をタブに入れるのに本当に苦労しています。XMLファイルを解析してリストに追加するアクティビティがあり、それ自体で完全に機能します。タブで呼び出すと機能しません(恐ろしい「申し訳ありません!何とか何とか..予期せず停止しました」というプロンプトが表示されます...ところで、マニフェストを実行しました)。

アクティビティを1つのアクティビティとして機能するように移行しました、出来上がり!機能した!!!しかし、これは私たちがこのプロジェクトでやりたかった方法ではありません-私たちは本当に別々の活動をする必要があります。

多くの人がタブとアクティビティが一緒にうまく機能しないことを知っていたので、それを回避する方法はありますか?ある種の乳化剤かもしれませんか?

コードは次のとおりです。

import android.app.Activity; import android.content.Intent; android.os.Bundleをインポートします。import 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();
    }
}

これが活動の1つです...

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 に答える