Saturday, August 6, 2011

android list view with adepter , aleart dialoge box EXAMPLE IN ANDROID



public class ListviewandroidActivity extends Activity {
/** Called when the activity is first created. */
TextView selection;

private ListView lv1;
private String lv_arr[]={"Android","iPhone","BlackBerry","AndroidPeople","Algeria", "Argentina", "Australia",
"Brazil", "Cote d'Ivoire", "Cameroon",
"Chile", "Costa Rica", "Denmark",
"England", "France", "Germany",
"Ghana", "Greece", "Honduras",
"Italy", "Japan", "Netherlands",
"New Zealand", "Nigeria", "North Korea",
"Paraguay", "Portugal","Serbia",
"Slovakia", "Slovenia", "South Africa",
"South Korea", "Spain", "Switzerland",
"United States", "Uruguay"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
selection=(TextView)findViewById(R.id.textView1);

lv1=(ListView)findViewById(R.id.ListView01);
// By using setAdpater method in listview we an add string array in list.
lv1.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1, lv_arr));
lv1.setTextFilterEnabled(true);

lv1.setOnItemClickListener(new OnItemClickListener()
{

@Override
public void onItemClick(AdapterView a, View v, int position, long id) {

AlertDialog.Builder adb=new AlertDialog.Builder(ListviewandroidActivity.this);
adb.setTitle("LVSelectedItemExample");
adb.setMessage("Selected Item is = "+lv1.getItemAtPosition(position));
adb.setPositiveButton("Ok", null);
adb.show();

}
});

}



}



............
main.xml
...............



http://schemas.android.com/apk/res/android">








--
krishnachary

No comments:

Post a Comment