gpt4 book ai didi

android - 如何在对话框中设置 ListView 的 "onItemSelectedListener"。安卓

转载 作者:行者123 更新时间:2023-11-29 22:22:46 25 4
gpt4 key购买 nike

大家好,我在对话框中设置了一个 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();
}

最佳答案

试试这个,

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

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

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

关于android - 如何在对话框中设置 ListView 的 "onItemSelectedListener"。安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6721838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com