我有ListView
个ImageButton
和TextView
s,ImageView
。如何在onListItemClick
中针对每个ListView
的个别操作执行ImageButton
。
public class AndroidThumbnailList extends ListActivity{
..........
ib2=(ImageButton)findViewById(R.id.imageButton2);
ib3=(ImageButton)findViewById(R.id.imageButton3);
ib1=(ImageButton)findViewById(R.id.imageButton1);
public class MyThumbnaildapter extends ArrayAdapter<String>{
public MyThumbnaildapter(Context context, int textViewResourceId,String[] objects) {
super(context, textViewResourceId, objects);
// TODO Auto-generated constructor stub
}
public View getView(int position, View convertView, ViewGroup parent) {
.........
}
}
protected void onListItemClick(ListView l, View v, int position, long id) {
Log.e("video", "called");
super.onListItemClick(l, v, position, id);
if(v.equals(ib1)){
....
}
if(v.equals(ib2)){
....
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new MyThumbnaildapter(AndroidThumbnailList.this, R.layout.row, _videosId));
}
}
如果我触摸ImageButton no action is done and the
ImageButton也未突出显示。
我的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="100dp" android:descendantFocusability="blocksDescendants">
<image view>....</image view>
<LinearLayout android:orientation="vertical" android:descendantFocusability="blocksDescendants"
<ImageButton android:id="@+id/imageButton1 ... ></ImageButton>
<ImageButton android:id="@+id/imageButton2 ... ></ImageButton>
<ImageButton android:id="@+id/imageButton3 ... ></ImageButton>
请帮帮我。
答案 0 :(得分:1)
您必须在Button
的{{1}}中为每个getView()
设置监听器。
检查this thread。
答案 1 :(得分:0)
首先,您使用的是ListView
还是LinearLayout
? ListActivity
与ListView
一起使用,我看不到你的ImageButton
。您已使用LinearLayout而已经提供了自己的onListItemClick
s,这些OnClickListener
不是由适配器创建的,因此不使用getView()
。
第二个(这只是意见,你可以让它在没有它的情况下工作),恕我直言,你最好在onListItemClick
中定义项目时定义{{1}},而不是使用{{1}}。
答案 2 :(得分:0)
您可以为每个onClick()
设置个人ImageButton
事件处理程序。
您必须声明上下文的方法(通常是您的Activity
):
public void onClickHandler(View v)
有关详细信息,请参阅ImageButton和onClick()的Javadoc。