简体   繁体   English

如何在Android中创建自定义列表视图

[英]How to create a custom listview in android

I want to create a list view custom like this link : http://sites.google.com/site/androideyecontact/_/rsrc/1238086823282/Home/android-eye-contact-lite/eye_contact-list_view_3.png?height=420&width=279 我想创建一个类似于此链接的列表视图自定义: http : //sites.google.com/site/androideyecontact/_/rsrc/1238086823282/Home/android-eye-contact-lite/eye_contact-list_view_3.png?height= 420&width = 279

so far I have made a list view with text, and I am not extending list Activity, but I am extending Activity only. 到目前为止,我已经用文本制作了一个列表视图,并且我没有扩展列表活动,而是仅扩展了活动。

please if someone can provide me with a code for this. 如果有人可以为此提供代码,请。

Thanks alot 非常感谢

Cheers 干杯

Kai

Check out this constructor for SimpleAdapter: 查看此SimpleAdapter的构造函数:

http://bit.ly/99OFSo http://bit.ly/99OFSo

Essentially, you create a custom layout to represent each row. 本质上,您将创建一个自定义布局来表示每一行。 Assign id's to the ImageView and TextView elements in this layout. 将ID分配给此布局中的ImageView和TextView元素。 You create a List<? extends Map<String, ?>> 您创建List<? extends Map<String, ?>> List<? extends Map<String, ?>> object to represent your data. List<? extends Map<String, ?>>对象以表示您的数据。 Each item in the list is a Map<String, [some object]> that represents a key and value for each piece of data you want to display. 列表中的每个项目都是Map<String, [some object]> ,它表示要显示的每个数据的键和值。 The third argument to the constructor is the id of the row layout. 构造函数的第三个参数是行布局的ID。 The fourth argument is an array of strings representing the keys for each piece of data in the Map you created earlier, and the fifth argument is an array of int id's of the ImageView and TextView elements in your layout (in corresponding order to the string array in the previous argument). 第四个参数是一个字符串数组,表示您先前创建的Map中每个数据的键,第五个参数是布局中ImageView和TextView元素的int id数组(按与字符串数组相对应的顺序)在上一个参数中)。

I've got something like the following: 我有类似以下内容:

ListView someListView= (ListView)findViewById(R.id.someListView);
SimpleAdapter adapter = new SimpleAdapter(
                    this,
                    someHelperMethodThatReturnsMyList(),
                    R.layout.custom_row,
                    new String[] { "field1", "field2", "field3" },
                    new int[] { R.id.txtField1, R.id.txtField2, R.id.imgField3}
                    );
            someListView.setAdapter(adapter);

This should help.- http://androidcocktail.blogspot.in/2012/03/custom-listview-in-android.html . 这应该有帮助。- http://androidcocktail.blogspot.in/2012/03/custom-listview-in-android.html In the example shown, replace the ListActivity with Activity and also define your own layout. 在所示的示例中,将ListActivity替换为Activity并定义自己的布局。 That should solve your issue. 那应该解决您的问题。

There is a really nice tutorial (one of literally thousands) which you could follow: 您可以遵循一个非常好的教程(实际上是数千个教程):

http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/ http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

If you have problem and post your code, we could also help you to find your error 如果您有问题并发布代码,我们也可以帮助您查找错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM