我在点击listView打开对话框时发现了一个问题。我在下面给出了返回的代码,如果有任何错误,请检查它。
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(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();
}
});
}
答案 0 :(得分:2)
builder.show()
- 因此不显示对话框
答案 1 :(得分:1)
在onItemClick
方法
AlertDialog alert = builder.create();
alert.show();