1

I want to add just one checkbox in a listview, I was researching and just found how to make it with checkbox in all its rows but I want it in just one row.

Thanks in advance

--edit--

thank you @Gaurav, I was researching and I could do it but now when I try to click the item with the checkbox it wasn't clicked

BaseAdapter

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;
}

Main

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);

what could be the problem?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Alexander Rojas
  • 125
  • 3
  • 14

1 Answers1

0

In the BaseAdapater Class in the getView u can try this

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;
        } 

For checked checkbox try this

 CheckBox checkBox = (CheckBox)v.findViewById(R.id.Checkbox);
        checkBox.setChecked(!checkBox.isChecked());
Developer
  • 6,292
  • 19
  • 55
  • 115
  • this will make it checked when it is not checked – Developer Aug 29 '13 at 09:56
  • that is not the problem, I can set the checkbox checked or not, but when I try to touch the row with the checkbox it doesn't click. – Alexander Rojas Aug 29 '13 at 10:01
  • i am not getting what u want to ask me please explain it more so that i can help u or mail me if u can – Developer Aug 29 '13 at 10:03
  • in this [first picture](https://dl.dropboxusercontent.com/u/43966800/Screenshot_2013-08-29-04-12-10.png) the row what I clicked is in blue obviously but in the [second](https://dl.dropboxusercontent.com/u/43966800/Screenshot_2013-08-29-04-12-25.png) I try to click it and it doesn't click. – Alexander Rojas Aug 29 '13 at 10:25
  • see this might help u http://stackoverflow.com/questions/12051813/android-listactivity-oncheckedchangelistener/12052585#12052585 – Developer Aug 29 '13 at 10:32
  • but I have the onClickListener, what happens is that the row with checkbox doesn't select – Alexander Rojas Aug 29 '13 at 10:38
  • I got it solved. Just had to set focusable and focusonTouchMode properties of checkbox to false.[here](http://stackoverflow.com/questions/15859134/listitem-click-doesnt-work-with-checkboxes-android) @Gaurav I could do it thanks to you – Alexander Rojas Aug 30 '13 at 11:49
  • don't tell that, you help me with the baseAdapter without it I wouldn't have been able to start so thanks @Gaurav – Alexander Rojas Aug 30 '13 at 11:59
  • if u think it's u r kindness u r always welcome for any help let me know – Developer Aug 30 '13 at 13:11