我对ArrayAdapter感到困惑。我有一个列表视图,由子视图组成。
每个子视图包含一个txtview和一个开关。
现在,我可以用我的项目打印出所有列表,但我有2个问题:
以下是我所拥有的:
public class PersAjoutOpAdapter extends ArrayAdapter {
static class ViewHolder {
public TextView txt_pers;
public Switch switch_pers;
}
private LayoutInflater inflater;
private boolean tous_coches = false;
private ImageView img_check_all_pers_op;
private ArrayList<Boolean> v_switchs;
private boolean en_train_de_checker_all;
public PersAjoutOpAdapter(Context p_context, ImageView p_img_check_all_pers_op) {
super(p_context, R.layout.item_pers_ajout_op, Friendly_Account.projet_actu.getPers_dans_projet());
inflater = LayoutInflater.from(p_context);
img_check_all_pers_op = p_img_check_all_pers_op;
v_switchs = new ArrayList<Boolean>(Friendly_Account.projet_actu.getPers_dans_projet().size());
for (int i=0 ; i<Friendly_Account.projet_actu.getPers_dans_projet().size() ; i++) {
v_switchs.add(i, false);
}
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
View rowView = convertView;
if (rowView == null) {
rowView = inflater.inflate(R.layout.item_pers_ajout_op, null);
holder = new ViewHolder();
holder.txt_pers = (TextView) rowView.findViewById(R.id.item_pers_ajout_op_prenom_nom);
holder.switch_pers = (Switch) rowView.findViewById(R.id.item_pers_ajout_op_switch);
rowView.setTag(holder);
holder.switch_pers.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
}
});
}else {
holder = (ViewHolder) rowView.getTag();
}
Personne pers = Friendly_Account.projet_actu.getPers_dans_projet().get(position);
holder.txt_pers.setText(pers.getPrenom());
holder.switch_pers.setChecked(v_switchs.get(position));
return rowView;
}
你能帮我解决这两点吗?
感谢。