List View in Android

Step 1. create a xml file name as “friend_detail.xml” in layout .

Step 2. Add a list View .

Step 3 . Create a class file in src name as .

Step4 . Write following Code in OnCreate method.

final ListView listview = (ListView) findViewById(;

String[] values = new String[] { “Android”, “iPhone”, “WindowsMobile”,

“Blackberry”, “WebOS”, “Ubuntu”, “Windows7”, “Max OS X”,

“Linux”, “OS/2”, “Ubuntu”, “Windows7”, “Max OS X”, “Linux”,

“OS/2”, “Ubuntu”, “Windows7”, “Max OS X”, “Linux”, “OS/2”,

“Android”, “iPhone”, “WindowsMobile” };

final ArrayList<String> list = new ArrayList<String>();

for (int i = 0; i < values.length; ++i) {



final StableArrayAdapter adapter = new StableArrayAdapter(this,

android.R.layout.simple_list_item_1, list);


Step 5. Create a function after onCreate function .

privateclass StableArrayAdapter extends ArrayAdapter<String> {

HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();

public StableArrayAdapter(Context context, int textViewResourceId,

List<String> objects) {

super(context, textViewResourceId, objects);

for (int i = 0; i < objects.size(); ++i) {

mIdMap.put(objects.get(i), i);




publiclong getItemId(int position) {

String item = getItem(position);




publicboolean hasStableIds() {




Step 6 . Import required Class if any error occure.

Best of Luck.



One thought on “List View in Android

Add yours

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at

Up ↑

%d bloggers like this: