タブホストのタブの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));
}
}
あなたはリストとでframeLayoutを交換し@androidするリスト上のIDを設定してみました:ID/tabcontent? – jsmith
なぜ私はそれをしますか?ドキュメントによると、あなたはタブを含むframelayoutを持っている必要があります... – Barak