ListView实例是Layout的一部分。
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/launch"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView android:id="@+id/resultlist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:footerDividersEnabled="true" >
</ListView>
<Button android:id="@+id/start"
android:text="Predict!"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
...
</FrameLayout>
</LinearLayout>
我想用id=resultlist来填充元素。当然,我已经为ListView的内容字符串开发了特殊的适配器和布局。代码看起来像
ListView view = (ListView) findViewById(R.id.resultlist);
MyAdapter adapter = new MyAdapter(
new MyItem(R.drawable.class_01, "AUTO", 1, 0.0f),
new MyItem(R.drawable.class_02, "BUS", 2, 0.0f),
);
view.setAdapter(adapter);
setContentView(view);
但它工作错误。我在设备上看不到任何东西。(我相信我必须在这里使用任何地方我的xml布局ListView字符串和LayoutInflater实例,但在哪里??)
谢谢。
是否在整个活动布局上调用"setContentView" ?如果没有,这可能解释了问题。