开发者

How to create a custom listview in android

开发者 https://www.devze.com 2022-12-30 08:17 出处:网络
I want to create a list view custom like this link :http://sites.google.com/site/androi开发者_运维百科deyecontact/_/rsrc/1238086823282/Home/android-eye-contact-lite/eye_contact-list_view_3.png?height=

I want to create a list view custom like this link : http://sites.google.com/site/androi开发者_运维百科deyecontact/_/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:

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. You create a List<? extends Map<String, ?>> object to represent your data. 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. The third argument to the constructor is the id of the row layout. 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).

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. In the example shown, replace the ListActivity with Activity and also define your own layout. 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/

If you have problem and post your code, we could also help you to find your error

0

精彩评论

暂无评论...
验证码 换一张
取 消