我的名單將在對話框中顯示,當用戶點擊按鈕,我想 檢查用戶setOnItemClickListener對話框不工作
點擊,但它不工作的項目。我的代碼如下:
private void showEditImageList() {
final String names[] ={"A","B","C","D","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t"};
AlertDialog.Builder alertDialog = new AlertDialog.Builder(SlotInformationActivity.this);
LayoutInflater inflater = getLayoutInflater();
View convertView = (View) inflater.inflate(R.layout.edit_image_list, null);
//convertView.setClickable(true);
//convertView.setOnClickListener(myClickListener);
alertDialog.setView(convertView);
alertDialog.setTitle("Tools");
ListView lv = (ListView) convertView.findViewById(R.id.editImageList);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, names);
lv.setClickable(true);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
System.out.println("Click position:" + position);
}
});
alertDialog.show();
}
請幫忙,謝謝。
對於文件中的代碼edit_image_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/editImageList"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
</LinearLayout>
嘗試從刪除setClickable()你列表顯示。不確定,但也許攔截事件發生在這裏onItemClick不會觸發。 – Viacheslav
而不是System.out.println();使用Log.d(「MY_APP」,「Click position:」+ position);並選擇logcat中的調試選項 –