// TODO Auto-generated method stub
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(
ListAlertDailog.this);
alertBuilder.setIcon(R.drawable.ic_launcher);
alertBuilder.setTitle("Select Mobile OS:-");
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
ListAlertDailog.this,
android.R.layout.select_dialog_item);
arrayAdapter.add("Android");
arrayAdapter.add("IOS");
arrayAdapter.add("Windows");
arrayAdapter.add("Bada");
arrayAdapter.add("BlackBerry OS");
arrayAdapter.add("Symbian OS");
alertBuilder.setNegativeButton("Cancle",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
}
});
alertBuilder.setAdapter(arrayAdapter,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
String strOS = arrayAdapter.getItem(which);
Toast.makeText(getApplicationContext(),
"On click selected " + strOS, Toast.LENGTH_SHORT)
.show();
dialog.dismiss();
}
});
final AlertDialog alertDialog = alertBuilder.create();
alertDialog.setOnShowListener(new OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
// TODO Auto-generated method stub
ListView listView = alertDialog.getListView();
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(
AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
String strOS = arrayAdapter.getItem(position);
Toast.makeText(getApplicationContext(),
"Long Press " + strOS,
Toast.LENGTH_SHORT).show();
alertDialog.dismiss();
return true;
}
});
}
});
alertDialog.show();