No se pueden obtener los valores correspondientes de las casillas de verificación en las que se hizo clic en un ListView

Esta CheckBox en un parche de ListView is driving me nuts. I've searched a lot about this on StackOverflow but I'm not able to fix this.

The problem is that I'm having a custom adapter for ListView in which I'm inflating the CheckBox.

Aquí está el código:

public class settingadapter extends BaseAdapter{

    private Activity recievedactivity;

    private String[] recieveddescription;
    private String[] recusername;
    private String allitems="";
    private String[] itemchecked;

    private static LayoutInflater inflator=null;


    public settingadapter(Activity recactivity,String[] username, String[] recdescription ){
        recievedactivity=recactivity;
        recusername=username;
        recieveddescription=recdescription;

        inflator=(LayoutInflater)recievedactivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);



    }
    public settingadapter(Activity recactivity,String[] username, String[] recdescription ,String all){
        recievedactivity=recactivity;
        recusername=username;
        recieveddescription=recdescription;
        allitems=all;
        inflator=(LayoutInflater)recievedactivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);


    }


    public int getCount() {
        // TODO Auto-generated method stub
        return recusername.length;
    }

    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }
    static class ViewHolder{
        TextView usernameTextView;
        TextView statusTextView;
        CheckBox checkView;
    }

    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        final ViewHolder viewHolder;

        if(convertView== null)
        {
            viewHolder=new ViewHolder();

            convertView=inflator.inflate(R.layout.item, null);

            viewHolder.usernameTextView=(TextView)convertView.findViewById(R.id.textView1);
            viewHolder.statusTextView=(TextView)convertView.findViewById(R.id.text);
            viewHolder.checkView=(CheckBox)convertView.findViewById(R.id.checkBox1);





            convertView.setTag(viewHolder);


        }else{
            viewHolder=(ViewHolder)convertView.getTag();
        }
            viewHolder.usernameTextView.setText(recusername[position]);
            viewHolder.statusTextView.setText(recieveddescription[position]);
             //Add listener to the checkbox


            System.out.println("testing alpha"+recusername[position]);

            if(allitems.equals("All")){
                viewHolder.checkView.setChecked(true);
            }
            else if (allitems.equals("---Select User---")){
                viewHolder.checkView.setChecked(false);
            }
            else
             return convertView;  
            //image.setBackgroundResource(R.drawable.check);



            return convertView;



    }

}

Now in this how do I get which CheckBox is clicked and how can I get the corresponding text also?

preguntado el 31 de julio de 12 a las 12:07

1 Respuestas

Please check these codes

Here in ans the person has added onclick event and getting the tag. Android cómo identificar un elemento en la vista de lista con casilla de verificación

Same code without onclick for checkboxes http://windrealm.org/tutorials/android/listview-with-checkboxes-without-listactivity.php

Espero que te ayude :)

contestado el 23 de mayo de 17 a las 12:05

thank u so much Avinash Sahu...it was really a helping code although m unable to vote this answer up coz of low reputations...thnk u soooooooooooooooooooooooo very much....at last android kings rocks.. - moni

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.