我有一個由TextView,ImageView,ImageButton組成的列表視圖和自定義佈局。我希望我的圖像按鈕的行爲與RadioButton類似。但是我的onListItemClick事件沒有被調用。onListItemClick不會在android中調用嗎?
public class MyListAdapter extends BaseAdapter {
Context context;
ArrayList<String> text;
ArrayList<String> Count;
int count;
public MyListAdapter(Context ctx, ArrayList<String> text, ArrayList<String> Count) {
this.context = ctx;
this.textAnswers = text;
this.optionCount = Count;
}
@Override
public int getCount() {
return Count.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.custom_layout, null);
}
ImageButton choice = (ImageButton)convertView.findViewById(R.id.ImageButton);
if(imageChoice != null) {
choice.setImageResource(R.drawable.radio_unselected);
}
TextView txt = (TextView)convertView.findViewById(R.id.TextView);
txt.setText(Count.get(position));
TextView txtText = (TextView)convertView.findViewById(R.id.TextViewAnswer);
txtText.setText(textAnswers.get(position));
return convertView;
}
}
而且我onListItemClick如,
@Override
protected void onListItemClick(ListView listView, View v, int position, long id) {
super.onListItemClick(listView, v, position, id);
ImageButton choice = (ImageButton)v.findViewById(R.id.ImageButton);
choice.setImageResource(R.drawable.radio_selected);
}
現在PLZ任何一個可以幫助給我的ImageButton像單選按鈕的行爲。我錯過的最重要的是我的onListItemClick沒有被調用。 另外我已經設置了我的custom_layout上所有控件的android:focusable =「false」android:focusableInTouchMode =「false」android:clickable =「false」。 在此先感謝。
你調用了'setOnItemClickListener'嗎? – MByD
@MByD不,我沒有叫setOnItemClickListener ..我必須嗎? – Panache
是的,你需要將它設置爲監聽器,否則,它將如何被調用? – MByD