はあなたのリストにフラグを追加してみ管理するために、1つの以上のUIオブジェクトにカスタムレイアウトをしている場合ArrayAdapterを使用しないでください
public class Country {
public String name;
public String code;
public String abbreviation;
public boolean selected = false; //--> example this flag
public int image;
}
アダプタを変更したい
public class CountryCodeAdapter extends BaseAdapter {
private Context context;
private List<Country> countryList;
public CountryCodeAdapter(Context context, List<Country> countryList) {
this.context = context;
this.countryList = countryList;
}
@Override
public int getCount() {
return countryList.size();
}
@Override
public Object getItem(int position) {
return countryList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.adapter_country_code, parent, false);
viewHolder = new ViewHolder(convertView);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
Country country = countryList.get(position);
viewHolder.tv_item_country_name.setText(country.getName());
String plus = context.getResources().getString(R.string.plus);
viewHolder.tv_item_country_code.setText(plus.concat(country.getCode()));
int image = country.getImage();
if (image != -1) {
viewHolder.iv_item_country.setImageResource(image);
}
return convertView;
}
public void updateList(List<Country> countryList) {
this.countryList = countryList;
notifyDataSetChanged();
}
static class ViewHolder {
@Bind(R.id.iv_item_country)
ImageView iv_item_country;
@Bind(R.id.tv_item_country_name)
TextView tv_item_country_name;
@Bind(R.id.tv_item_country_code)
TextView tv_item_country_code;
public ViewHolder(View view) {
ButterKnife.bind(this, view);
}
}
}
フラグの場合は、アダプタの外でこれを実行します。
CountryCodeAdapter adapter = new CountryCodeAdapter(activity, countryList);
//eg. you may change the 1st element in countryList selected flag into true and //call updateList
if (adapter != null) {
adapter.updateList(countryList);
}
このフラグを使用して、アダプタ内のチェックボックスを設定します。
http://stackoverflow.com/a/10896140/726863 –