如何使用两个ListView控件在一个屏幕? [英] How to use Two ListView in one screen?
本文介绍了如何使用两个ListView控件在一个屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在一个ListActivity使用两个列表视图。我怎样才能做到这一点?请帮我在一个ListActivity创建两个不同的列表视图。
I want to use two list view in one ListActivity. How can I do this? Please help me to create two different list view in one ListActivity.
谢谢
迪帕克
推荐答案
只要创建一个名为main.xml中的文件像XML:
Just create an XML named main.xml file like:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent"
>
<ListView android:id="@+id/ListView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
/>
<ListView android:id="@+id/ListView02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/ListView01"
android:gravity="center_horizontal"
/>
</RelativeLayout>
通过加载这个XML文件:的setContentView(R.layout.main);
在你的onCreate功能
Load this xml file via: setContentView(R.layout.main);
in your onCreate function.
ListView list1 = ((ListView) findViewById(R.id.ListView01));
允许您访问第一个列表,那么你可以申请你的适配器的List1。通过交换1到2就可以访问第二个ListView的为好。
allows you to access the first list and then you can apply your adapter to list1. By exchanging 1 to 2 you can access the second ListView as well.
这篇关于如何使用两个ListView控件在一个屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文