如何在Android上使用多个列表视图在一个单一的活动?

编程入门 行业动态 更新时间:2024-10-28 09:19:35
本文介绍了如何在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。首先,所有重要的设计文件(从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上使用多个列表视图在一个单一的活动?

本文发布于:2023-05-31 10:09:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/389615.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   视图   如何在   列表   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!