How to open dialog from listview
I have found a problem while opening dialog on click of listView..the code i have return is given below please check it if there is any error there..
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_info);
ListView lv2;
String lv_arr1[]={"Language:NotSpecified"};
lv2=(ListView)findViewById(R.id.listViewInfo1);
lv2.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , lv_arr1));
ListView lvInfo1;
ListViewInfo adapter;
String lvTitle[]={"online"};
String lvDesc[]={"Change Status"};
adapter = new ListViewInfo(开发者_JS百科this, lvTitle,lvDesc);
lvInfo1=(ListView)findViewById(R.id.listViewInfo2);
lvInfo1.setAdapter(adapter);
lvInfo1.setOnItemClickListener(this);
}
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id)
{
final CharSequence[] items = {"Online", "Away", "Do not distrub","Invisible","Offline"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Change Status");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
}
builder.show()
is missing at the end of dialog initialization - so dialog is not displayed
Add the following code at the end of your onItemClick
method
AlertDialog alert = builder.create();
alert.show();
精彩评论