ListView控件OnItemClickListener没有响应? [英] ListView OnItemClickListener Not Responding?
问题描述
我到处找一个解决办法,但我不能想出如何实现它。我的 OnItemClickListener
被禁用某种方式对我的的ListView
行,因为我有一个的ImageButton
在该行的布局,接管的焦点。已经有,我发现了很多问题,但他们都没有得到任何地方我。
I've looked everywhere for a solution to this, but I can't figure out how to implement it. My OnItemClickListener
was disabled somehow on my ListView
rows, because I have an ImageButton
in the row layout, which takes over the focus. There have been numerous questions I've found, but none of them have gotten me anywhere.
我检查<一href="http://stackoverflow.com/questions/2097643/layout-question-onitemclicklistener-not-working-now">this的问题,但我不能真正使头或它的尾巴。我只是需要一种方式来获得行点击,这样我可以检测一个行pssed $ P $。龙preSS和重点做工精细。
I've checked this question, but I couldn't really make heads or tails of it. I just need a way to get the rows clickable so that I can detect when a row is pressed. Long press and focus work fine.
推荐答案
而不是一个 OnItemClickListener 的,添加的 OnClickListener 的每一个你的意见,从您的适配器返回。你需要使用 setItemsCanFocus
设置你的清单:
Instead of an OnItemClickListener, add an OnClickListener to each of your views returned from your adapter. You'll need to use setItemsCanFocus
setting up your list:
ListView list = (ListView) findViewById(R.id.myList);
list.setAdapter(new DoubleClickAdapter(this));
list.setItemsCanFocus(true);
,然后在你的适配器的的 getView
,这将产生一个可点击的一行。假定按钮是在膨胀的xml
and then in your Adapter's getView
, this will yield a clickable row. The button is assumed to be in the inflated xml.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = View.inflate(context, R.layout.cell, null);
view.setClickable(true);
view.setFocusable(true);
view.setBackgroundResource(android.R.drawable.menuitem_background);
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(context).setTitle("touched").show();
}
});
return view;
}
这篇关于ListView控件OnItemClickListener没有响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!