的列表視圖中執行onListItemClick我有一個ListView
三個ImageButton
s和TextView
s,ImageView
。我如何在ListView
中爲ImageButton
單獨執行onListItemClick
。我該如何在android
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>
請幫助我。
我執行如下:我得到空指針異常請幫我 類實現OnclickListener { ib1 =(ImageButton)findViewById(R.id.image1); ib1.setOnclickListener(this); //空指針異常 public void onClickHandler(View v){if(v.getid.equals(R,id.image){...} } } – 2011-06-09 07:44:54