Adil Bhatty
Adil Bhatty

Reputation: 17340

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

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

Upvotes: 1

Views: 17439

Answers (3)

James Bond
James Bond

Reputation: 31

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.

Upvotes: 3

Rich
Rich

Reputation: 36866

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);

Upvotes: 4

anon
anon

Reputation:

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

Upvotes: 2

Related Questions