2
皆リストラジオボタンを追加してラジオボタンを追加したカスタムリストビューを作成していますが、ラジオグループエラーのあるリストビュー
public class InteractiveArrayAdapter extends ArrayAdapter<Model> {
String tag = "Events";
private final List<Model> list;
private final Activity context;
public InteractiveArrayAdapter(Activity context, List<Model> list) {
super(context, R.layout.rowbuttonlayout, list);
this.context = context;
this.list = list;
}
static class ViewHolder {
protected TextView text;
protected CheckBox checkbox,checkbox1;
protected RadioGroup mgroup;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.d(tag," 3");
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.rowbuttonlayout, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.label);
//viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check);
//viewHolder.checkbox1 = (CheckBox) view.findViewById(R.id.checkbox1);
viewHolder.mgroup = (RadioGroup) view.findViewById(R.id.radioGroup1);
final RadioButton[] mbutton=new RadioButton[5];
for(int l=0;l<5;l++){
mbutton[l]=new RadioButton(context);
mbutton[l].setText("test"+l);
viewHolder.mgroup.addView(mbutton[l]);
}
viewHolder.mgroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup mRadioGroup, int checkedId) {
for(int i=0; i<mRadioGroup.getChildCount(); i++) {
RadioButton btn = (RadioButton) mRadioGroup.getChildAt(i);
//int t=table.indexOfChild(table_row);
//System.out.println(t);
int t=mRadioGroup.getId();
System.out.println(t);
if(btn.getId() == checkedId) {
String text = btn.getText().toString();
// do something with text
Log.d(text," event1");
return;
}
}
}
});
view.setTag(viewHolder);
Log.d(tag,"me");
} else {
view = convertView;
Log.d(tag,"meeee");
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position).getName());
Log.d(tag," event7");
return view;
}
}
を13行が選択つつあると私は第六に、同じボタン2行目のいずれかのボタンを選択すると、8日、12行目は、私がここで間違ってやっているものを選択しつつあり、私のアダプタクラスI私の作業コードを投稿して、他の人に参考になるようにしてください。
public class InteractiveArrayAdapter extends ArrayAdapter<Model> implements OnClickListener {
String tag = "Events";
private final List<Model> list;
private final Activity context;
int li,jh;
public InteractiveArrayAdapter(Activity context, List<Model> list) {
super(context, R.layout.rowbuttonlayout, list);
this.context = context;
this.list = list;
}
static class ViewHolder {
protected TextView text;
protected CheckBox checkbox,checkbox1;
protected RadioGroup mgroup;
protected RadioButton mbutton;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
//Log.d(tag," 3");
View view =null;
if (convertView == null) {
//System.out.println("ok");
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.rowbuttonlayout, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.label);
viewHolder.mgroup = (RadioGroup) view.findViewById(R.id.radioGroup1);
final RadioButton[] mbutton=new RadioButton[5];
for(int l=0;l<5;l++){
mbutton[l]=new RadioButton(context);
mbutton[l].setText("test"+l+position);
mbutton[l].setId(l+1);
mbutton[l].setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
RadioButton byt=(RadioButton) v;
byt.isChecked();
byt.getId();
Model element = (Model) viewHolder.mgroup.getTag();
element.setBte(byt.getId());
element.gte((String) viewHolder.text.getText());
System.out.println("givemeresult");
}
});
viewHolder.mgroup.addView(mbutton[l]);
}
view.setTag(viewHolder);
viewHolder.mgroup.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).mgroup.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
view.getTag()).mgroup.getTag();
holder.text.setText(list.get(position).getName());
if (list.get(position).getName()==list.get(position).done()){
holder.mgroup.check(list.get(position).isSelected());
}
else {
holder.mgroup.clearCheck();
}
return view;
}
申し訳ありませんが私はこのplatforに初心者です.because私はあなたがそれを説明するだろう取得できませんでしたm – Ghouse
こんにちは、誰でもちょうど私がそのセットholder.mgroup答えについて知らせてください。 – Ghouse
確かに。ビューはリストビューでリサイクルされます。 http://mobile.cs.fsu.edu/?p=527こちらをご覧ください。 "if(convertView == null)"のelse {}にradiobutton.setChecked(true | false)を設定する必要があります。 – Dante