[英]Android: how to create this kind of dynamic layout?
My aim is to display people/addresses in a list - but not just a simple list, rather a list of boxes that contain several information, in my case a number, the address and a type: 我的目的是在列表中显示人员/地址-而不只是一个简单的列表,而是一个包含多个信息的框列表,在我的情况下是一个数字,地址和类型:
The data structure for this are POJOs: 为此的数据结构是POJO:
Of course, there are more than 4 entries which means that there should be a scrollbar. 当然,有四个以上的条目,这意味着应该有一个滚动条。 My first idea: a
Scrollview
that contains a Linear Layout
. 我的第一个想法:包含
Linear Layout
的Scrollview
。 But I'm not sure about the content, means the boxes you can see above. 但我不确定内容,即您可以在上方看到的方框。
Thank you 谢谢
ListActivity
class ListActivity
类 Create a separate layout file for your item 为您的项目创建一个单独的布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" > <LinearLayout android:orientation="vertical" > <TextView /> <TextView /> </LinearLayout> </TextView> </LinearLayout>
ListActivity
which extends from ArrayAdapter
. ListActivity
创建一个内部类,该内部类从ArrayAdapter
扩展。 In the getView()
method, use LayoutInflater
to inflate yourItemLayout and update the TextView based on the position
values. getView()
方法中,使用LayoutInflater
膨胀yourItemLayout并根据position
值更新TextView。 onCreate
in the main class, call setListAdapter(new InnerClass(this,R.layout.yourItemLayout,list)
onCreate
调用setListAdapter(new InnerClass(this,R.layout.yourItemLayout,list)
You can refer customArrayAdapter to know how to custom ArrayAdapter works. 您可以参考customArrayAdapter来了解如何自定义ArrayAdapter。
Done and dusted. 尘埃落定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.