2012-02-12 6 views
0

タブホストのタブの1つとしてListViewを挿入しようとしています。私はウェブを精査して、彼らが働いていると言ういくつかの実装を見つけましたが、自分のプロジェクトでも、私のものに組み込まれていても、私にとってはそうではありません。TabHostのリストビューを(ビューではなく、アクティビティではなく)入れようとしています

私はLogCatでエラーは発生していませんが、クラッシュしない限り動作しますが、タブは空になります。

リストを提供している配列(tooldisplay)をチェックしています。

私はタブを設定するために別のアクティビティを起動する必要はありません。

setupdetail.xml:(非関連するコードを削除するには、編集)tabhostため

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:padding="5dp" > 
     <TextView 
      android:id="@+id/setupheader" 
      android:layout_width="fill_parent" 
      android:layout_height="20dp" 
      android:text="This will be the setup header" 
      android:textSize="15dp" /> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="30dp" 
      android:gravity="bottom" /> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5dp" > 
      <!-- General Info Tab --> 
      <LinearLayout 
       android:id="@+id/general_tab" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" > 
      </LinearLayout> 
      <!-- Tool Tab --> 
      <ListView 
       android:id="@+id/list1" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:drawSelectorOnTop="false" /> 
     </FrameLayout> 
    </LinearLayout> 
</TabHost> 

アクティビティ:

public class SetupDisplay extends TabActivity { 
    private String[] tooldisplay = new String[20]; 
    private ListView mListView; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.setupdetailmain); 
     // Set up tabs 
     TabHost tabHost = getTabHost(); 
     TabHost.TabSpec spec; 
     spec = tabHost.newTabSpec("general").setIndicator("General") 
       .setContent(R.id.general_tab); 
     tabHost.addTab(spec); 
     spec = tabHost.newTabSpec("tools").setIndicator("Tools") 
       .setContent(R.id.list1); 
     tabHost.addTab(spec); 
     // Load data into tooldisplay[] 
     // get view & set adapter 
     mListView = (ListView)findViewById(R.id.list1); 
     mListView.setAdapter(new ArrayAdapter<String>(this, 
       android.R.layout.simple_list_item_1, tooldisplay)); 
    } 
} 
+0

あなたはリストとでframeLayoutを交換し@androidするリスト上のIDを設定してみました:ID/tabcontent? – jsmith

+0

なぜ私はそれをしますか?ドキュメントによると、あなたはタブを含むframelayoutを持っている必要があります... – Barak

答えて

0

は私がずっとグーグル後に私の問題の原因を発見しました。後で同じ問題が出るかもしれない人のための回答を投稿する。

私は間違ったコンストラクタを使用していました。

私はレイアウト内に複数のテキストビューがあるので、アダプタのレイアウトとテキストビューを指定する必要があります(修正に関する私のコードは、私がカスタムリストレイアウトに切り替えたときに最初に投稿されたものと少し異なります私がコンストラクタの修正を行うまで、問題はまだそこに残っていました)。

mListView.setAdapter(new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1, tooldisplay)); 

は次のようになります。

ListView mListView = (ListView)findViewById(R.id.list1);   
    mListView.setAdapter(new ArrayAdapter<String>(this,   
      R.layout.listlayout, R.id.ListItem1, tooldisplay));   
関連する問題