我想在我的 ArrayAdapter 中设置一个切换按钮的 RadioGroup。我的列表中有两个选项,所以当我选择一个 ToggleButton 打开时,我希望另一个关闭。
这是我的 ArrayAdapter 代码:
public class MyAdapter extends ArrayAdapter<String>{
public MyAdapter(Context context, int textViewResourceId, ArrayList<String> objects) {
super(context, textViewResourceId, objects);
}
@Override
public View getDropDownView(int position, View convertView,ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
public View getCustomView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getActivity().getLayoutInflater();
final ViewHolder holder = new ViewHolder();
View row = inflater.inflate(R.layout.psip_settings_callquality_listitem, parent, false);
holder.itemTitle = (TextView) row.findViewById(R.id.txtCQViewItem);
holder.itemDesc = (TextView) row.findViewById(R.id.txtCQViewDesc);
holder.itemToggle = (ToggleButton) row.findViewById(R.id.togCQViewItem);
holder.itemToggle.setTag(position);
holder.itemToggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton togButton, boolean isChecked) {
}
});
holder.itemTitle.setText(sSettingTitles.get(position));
holder.itemDesc.setText(sSettingDesc.get(position));
return row;
}
private class ViewHolder {
TextView itemTitle;
TextView itemDesc;
ToggleButton itemToggle;
}
}
XML
<TextView
android:id="@+id/txtCQViewItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="@color/MiscBtnClick"
android:layout_margin="5dp" />
<TextView
android:id="@+id/txtCQViewDesc"
android:layout_width="wrap_content"
android:layout_below="@+id/txtCQViewItem"
android:layout_height="wrap_content"
android:textColor="@color/MiscBtnClick"
android:layout_toLeftOf="@+id/togCQViewItem"
android:layout_margin="5dp" />
<ToggleButton
android:id="@+id/togCQViewItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/txtCQViewItem"
android:layout_alignParentRight="true" />
任何帮助都会很棒。谢谢