如何在Android上使用多个列表视图在一个单一的活动? [英] How to use multiple listviews in a single activity on android?
问题描述
我有9列表视图应该受到单一的活动。所有列表可能/ maynot一次显示在屏幕上(全部在同一时间是好的)
I have 9 listviews which should come under single activity. All the lists may/maynot display at a time on the screen (all at a time is nice)
推荐答案
下面是同一活动中的一个体面的解决办法,以多个的ListView。首先,所有重要的设计文件(从<复制的href="http://stackoverflow.com/questions/3968171/android-split-the-screen-in-2-equals-parts-with-2-listviews">ANDROID :分割屏幕在2等于零件2列表视图... ,好!)。注意,列表视图嵌入在自身LinearLayouts,这是每一个权重相同。
Here is a decent solution to more than one ListView within the same Activity. First the all-important layout file (copied from ANDROID : split the screen in 2 equals parts with 2 listviews ..., good job!). Note that the ListViews are embedded in their own LinearLayouts, which are each equally weighted.
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ListView android:id="@+id/list1"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ListView android:id="@+id/list2"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
// Start java Code (you can figure out the imports)
public class AnActivity extends Activity {
private ListView lv1 = null;
private ListView lv2 = null;
private String s1[] = {"a", "b", "c", "d", "e", "f"};
private String s2[] = {"r", "s", "t", "u", "v", "w", "x"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get UI references.
//
lv1 = (ListView) findViewById (R.id.list1);
lv2 = (ListView) findViewById (R.id.list2);
lv1.setAdapter(new ArrayAdapter<String> (this, android.R.layout.simple_list_item_1, s1));
lv2.setAdapter(new ArrayAdapter<String> (this, android.R.layout.simple_list_item_1, s2));
} // onCreate()
} // class
很抱歉,如果有任何错别字。我编辑就在这里,在窗口,而不是在eclipse。祝你好运!
Sorry if there are any typos. I'm editing right here in the window, not in eclipse. Good luck!
这篇关于如何在Android上使用多个列表视图在一个单一的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!