[英]ListView OnItemClickListener not Working for Listview
I am using listview
with Customlist
Adapter, I am able to set data to list but not able to assign onItem click listener to list. 我使用
listview
与Customlist
适配器,我能够设定数据列表中,但无法指定onItem点击收听上市。 Some of the code snippet is as follows : 一些代码片段如下:
private ListView listview;
listview = (ListView) findViewById(R.id.mainOptionList);
customlistviewadapter = new CustomListViewAdapter(this, R.layout.listview_item_row, elements);
listview.setAdapter(customlistviewadapter);
With this I am able to assign data to list. 这样我就可以将数据分配给列表。 I have attached clicklistener as follows :
我已将clicklistener附加如下:
listview.setOnItemClickListener(this);
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
System.out.println("position" + position + " item at this position:" + adapter.getItemAtPosition(position));
}
Here I am not able to print output in logcat
. 在这里,我无法在
logcat
打印输出。 Can somebody help me to resolve this issue? 有人可以帮我解决这个问题吗?
In your custom file named listview_item_row set this properties 在名为listview_item_row的自定义文件中,设置此属性
android:focusable="false"
android:focusableInTouchMode="false"
for your all UI elements. 用于您的所有UI元素。
You just try to put toast on the click listener 您只是尝试在点击监听器上吐司
You just Use this code inside your Main Activity... 您只需在您的主要活动中使用此代码...
sListStudies.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view,
int position, long arg) {
Toast.makeText(
MainActivity.this,
"position" + position + " item at this position:"
+ adapter.getItemAtPosition(position),
Toast.LENGTH_LONG).show();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.