私は、TextView、ImageView、ImageButtonからなるリストビューとカスタムレイアウトを持っています。イメージボタンをRadioButtonのように動作させたいしかし、私のonListItemClickイベントは呼び出されていません。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);
}
、など
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今私のIMAGEBUTTONにラジオボタンのような振る舞いを与えるために、いずれかの助けをplzは。私が忘れた最も重要なのは、私のonListItemClickが呼び出されていないということです。 また、custom_layoutのすべてのコントロールのandroid:focusable = "false" android:focusableInTouchMode = "false" android:clickable = "false"を設定しました。 ありがとうございます。
あなたは 'setOnItemClickListener'を呼び出しましたか? – MByD
@MByDいいえ、私はsetOnItemClickListenerと呼ばれませんでした..私はする必要がありますか? – Panache
はい、それをリスナーとして設定する必要があります。それ以外の場合は、どのように呼び出されますか? – MByD