1

我只想在列表视图中添加一个复选框,我正在研究,只是发现如何在所有行中使用复选框,但我只希望它在一行中。

提前致谢

- 编辑 -

谢谢@Gaurav,我正在研究,我可以做到,但是现在当我尝试单击带有复选框的项目时,它没有被单击

基础适配器

public View getView(int arg0, View arg1, ViewGroup arg2) {
    View v = arg1;
    if(arg1 == null){
        LayoutInflater inf = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = inf.inflate(R.layout.row, null);
    }
    Articulos art = items.get(arg0);
    TextView nombre = (TextView) v.findViewById(R.id.tvNombreRow);
    nombre.setText(art.getNombre());
    CheckBox check = (CheckBox) v.findViewById(R.id.chkCuadroRow);
    check.setChecked(art.getEstado());
    if(art.getVisible()){
         check.setVisibility(View.VISIBLE);
    }else{
        check.setVisibility(View.INVISIBLE);
    }
    return v;
}

主要的

ArrayList<Articulos> arrayList = new ArrayList<Articulos>();
    Articulos articulos;
    articulos = new Articulos("Color de fondo",false,false);
    arrayList.add(articulos);
    articulos = new Articulos("Vencimiento de bonos",false,false);
    arrayList.add(articulos);
    articulos = new Articulos("Comparte esta aplicacion",false,false);
    arrayList.add(articulos);
    articulos = new Articulos("Visualizador de tiempo",true,true);
    arrayList.add(articulos);
    articulos = new Articulos("Configuración",false,false);
    arrayList.add(articulos);
    articulos = new Articulos("Tutorial",false,false);
    arrayList.add(articulos);
    articulos = new Articulos("Acerca de",false,false);
    arrayList.add(articulos);
    articulos = new Articulos("Salir",false,false);
    arrayList.add(articulos);

    BaseAdapterCustom adapter = new BaseAdapterCustom(this, arrayList);
    lstConfiguracion.setAdapter(adapter);

可能是什么问题呢?

4

1 回答 1

0

在 getView 的 BaseAdapter 类中,你可以试试这个

public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        vi = inflater.inflate(R.layout.your_layout, null);
         if(position = yourcondtion){
            //set the visibility of the checkbox true or false
         } 
            return vi;
        } 

对于选中的复选框,试试这个

 CheckBox checkBox = (CheckBox)v.findViewById(R.id.Checkbox);
        checkBox.setChecked(!checkBox.isChecked());
于 2013-08-29T07:47:57.467 回答