我在对话框片段中有多个选择ListView
,如下所示ArrayAdapter
:
public class AnswerListAdapter extends ArrayAdapter<String> {
private SparseBooleanArray mSelectedItemsIds;
private LayoutInflater inflater;
private Context mContext;
private List<String> list;
public AnswerListAdapter (Context context, int resourceId, List<String> list) {
super(context, resourceId, list);
mSelectedItemsIds = new SparseBooleanArray();
mContext = context;
inflater = LayoutInflater.from(mContext);
this.list = list;
}
private static class ViewHolder {
TextView itemName;
}
public View getView(int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null)
{
holder = new ViewHolder();
view = inflater.inflate(R.layout.list_item, null);
holder.itemName = (TextView) view.findViewById(R.id.txtAnswer);
view.setTag(holder);
} else
{
holder = (ViewHolder) view.getTag();
}
holder.itemName.setText(list.get(position));
return view;
}
public void toggleSelection(int position)
{
selectView(position, !mSelectedItemsIds.get(position));
}
public void selectView(int position, boolean value) {
if (value)
mSelectedItemsIds.put(position, value);
else
mSelectedItemsIds.delete(position);
notifyDataSetChanged();
}
public SparseBooleanArray getSelectedIds()
{
return mSelectedItemsIds;
}
}
我如何将.setEnable(false)
用于未选择的项目?
例如列表项目是:否,是,是-1,是-2。如果我选择否我想要禁用是项目