作者:mobiledu2502875577 | 来源:互联网 | 2023-07-04 19:55
ItseemslikemyListViewOnItemClickListenerdoesnotalwaysseemtobecalled.TheListViewusese
It seems like my ListView OnItemClickListener does not always seem to be called. The ListView uses embedded TextViews.
似乎我的ListView OnItemClickListener似乎并不总是被调用。 ListView使用嵌入式TextView。
If you click at the top or bottom 3px of each item then the listener does fire.
如果单击每个项目的顶部或底部3px,则侦听器会触发。
If you click on the text of the TextView then the listener does not fire as though it is consuming/blocking the click.
如果单击TextView的文本,则侦听器不会像消耗/阻止单击一样触发。
I have tried many combinations of adding focusable="false"
, clickable="false"
and focusableInTouchMode="false"
to the TextView and adding android:descendantFocusability="beforeDescendants"
to the root view.
我尝试了很多组合,将focusable =“false”,clickable =“false”和focusableInTouchMode =“false”添加到TextView,并将android:descendantFocusability =“beforeDescendants”添加到根视图中。
activity_local_explorer.xml
Activity
public class LocalExplorer extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_local_explorer);
String[] values = { "Hello", "My", "Friend"};
ListView listView = (ListView) findViewById(R.id.local_file_view);
listView.setAdapter(new ArrayAdapter<>(this, R.layout.activity_local_explorer, R.id.local_file_view_text, values));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView> adapterView, View view, int position, long id) {
String selectedValue = getItemAtPosition(position);
Snackbar.make(listView, selectedValue, 2).show();
}
});
}
Any help would be much appreciated as I have been spending hours on this simple activity!
任何帮助都会非常感激,因为我花了几个小时来完成这个简单的活动!
1 个解决方案