【发布时间】:2014-08-06 05:58:12
【问题描述】:
我正在开发 Android 应用程序,但我在使用 listview 时遇到了严重问题。
一开始我有一个 onItemClickListener,它运行良好,但现在,我在布局中添加了一些新功能,但它不起作用。
我的代码是:
lv = (ListView) findViewById(R.id.listChap);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(CapituloList.this,"Pulsado",Toast.LENGTH_SHORT).show();
Capitulo chap = (Capitulo) mAdapter.getItem(i);
Intent mIntent = new Intent(CapituloList.this, MangaView.class);
mIntent.putExtra("capitulo", chap);
startActivity(mIntent);
}
});
在 Capitulo 适配器中我有:
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.list_manga_item_view,null);
TextView tv = (TextView) view.findViewById(R.id.nombre_manga);
ImageButton ib = (ImageButton) view.findViewById(R.id.checked_icon);
ImageButton ib2 = (ImageButton) view.findViewById(R.id.unchecked_icon);
tv.setText(mItems.get(i).getCapitulo());
return view;
}
显然我想区分 ib、ib2 和布局的其余部分的触摸 可见的结果是:点击网址,我没有发布图片的信誉 http://i.imgur.com/kNXU8lE.png
提前致谢
编辑:已解决
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.list_manga_item_view,null);
TextView tv = (TextView) view.findViewById(R.id.nombre_manga);
final Capitulo chap = (Capitulo) this.getItem(i);
ImageButton ib = (ImageButton) view.findViewById(R.id.imageButton);
ib.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(mContext,"Button1 pressed",Toast.LENGTH_LONG).show();
}
});
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent mIntent = new Intent(mContext, MangaView.class);
mIntent.putExtra("capitulo", chap);
mContext.startActivity(mIntent);
}
});
ImageButton ib2 = (ImageButton) view.findViewById(R.id.imageButton2);
ib2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(mContext,"Button2 pressed",Toast.LENGTH_LONG).show();
}
});
tv.setText(mItems.get(i).getCapitulo());
return view;
}
【问题讨论】:
-
你在那些按钮上设置了 onItemClickListener 吗?
-
不,当它只是一个 TextView 时它确实有效,但现在它无法识别触摸事件
-
intenta ponerle un click listener a los imagebutton。 Dice que ahora no reacciona al pulsar ningun objeto de la lista?
-
试试这个答案,它解决了一个类似的问题:检测列表视图行中小部件的点击,而不是整个项目stackoverflow.com/questions/24170236/…
-
你想要什么?你是要点击 imagebutton1 和 imagebutton2 点击事件还是要检测整个列表项点击事件
标签: android listview touch-event