<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AdapterActivity" >
<ListView
android:id="@+id/list_id"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="10dp"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
</ListView>
</RelativeLayout>
package com.example.listtest;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
ListView listView;
static final String[] numbers = new String[] { "Mammooty", "Mohan Lal", "Amithab Bachan",
"Salman Khan", "Amir Khan", "Ram Charan",
"Allu Arjun", "Surya", "Vikram", "Vijay" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.list_id);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_selectable_list_item, numbers);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Toast.makeText(getApplicationContext(),
((TextView) v).getText(), Toast.LENGTH_SHORT).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Done...