如何在对话框中设置ListView“onItemSelectedListener”。 Android的

时间:2011-07-17 04:03:59

标签: android listview dialog listener android-listview

嘿伙计我在对话框设置中得到了一个ListView但是当我在对话框中设置onItemSelectedListener时,它甚至没有注册在对话框的ListView中选择了任何东西!有任何想法吗?这就是我所拥有的:

 Dialog dialog = new Dialog(DealActivity.this);
 dialog.setContentView(R.layout.test_list);
 dialog.setTitle("Test Dialog");
 dialog.setCancelable(true);
 dialog.setCanceledOnTouchOutside(true);
 ListView listView = (ListView) dialog.findViewById(R.id.listView);

 //DIDNT INCLUDE CODE HERE THAT SETS UP THE ADAPTER! 
 //THIS IS WHERE I SET UP THE LISTENER WITHIN THE DIALOG.

 listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {                              

     public void onItemSelected(AdapterView<?> parent,View arg1, int arg2, long arg3) {
        Log.d("clicked","clicked "+ listView.getItemSelectedPosition());
    }

    public void onNothingSelected(AdapterView<?> parent) {

    }
});
}
    dialog.show();
}

1 个答案:

答案 0 :(得分:2)

试试这个,

ListView list = (ListView) findViewById(R.id.listView);
list.setItemsCanFocus(false);

如果您对ListView中的每个项目都有一些控件,如CheckBox,Button等,请将其添加到其布局xml中。

android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"