我有一个ListView和自定义布局,其中包含TextView、ImageView和ImageButton。我希望我的ImageButton的行为类似于RadioButton。但是我的onListItemClick事件没有被调用。
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);
}
现在请任何人帮我将我的imagebutton的行为设置成类似于radiobutton的行为。最重要的是,我的onListItemClick没有被调用。 此外,我已经在我的custom_layout中将所有控件的android:focusable="false" android:focusableInTouchMode="false" android:clickable="false"设置好了。 提前致谢。
setOnItemClickListener
吗? - MByD