我有一个带有各种标签的应用程序(在tabhost上).每个选项卡都是一个扩展活动的活动,并且包含一些textfields
内容.
现在,我需要我的选项卡在listview中,但在Android开发人员指南的示例中,您必须扩展ListActivity而不是Activity.
基本上,我需要合并这两个教程:
如何在listview
不延伸listactivity
课程的情况下使用?
我的XML文件:
<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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"/>
</LinearLayout>
</TabHost>
Run Code Online (Sandbox Code Playgroud)
Mac*_*rse 18
它几乎是一样的.基于ListView的教程.
而不是做:
setListAdapter();
Run Code Online (Sandbox Code Playgroud)
请执行下列操作:
<ListView>
在您的布局中添加一个Activity
private ListView mListView;
在onCreate()
方法上这样做:
mListView = (ListView) findViewById(R.id.your_list_view_id);
mListView.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));
Run Code Online (Sandbox Code Playgroud)
我不记得是否ListActivity
提供更多东西.
你的TabHost也可以包含一个ListActivity
,因为它继承自Activity
.
但是,如果您想了解如何以任何方式在活动中添加列表视图,请按照这些说明操作.这很简单,Make Activity
a Listview
,在XML中添加一个.
使用findViewById()
让您的 ListView
.
归档时间: |
|
查看次数: |
10954 次 |
最近记录: |