Search code examples
androidandroid-listview

How to manipulate data in list view that is populated by custom cursor adapter


I have populated a list view using the custom cursor adapter, That listview consists of a checkbox and button in the below manner.

checkbox1 button1
checkbox2 button2
.
.
.

Now I want to navigate to another activity when click on the button in list view now my issue here is when I click on the button1 then I want to see the data in checkbox1 and similarly for other rows as well.

Now I am confused on how to maintain a sync between the checkbox and button and how to achieve the click functionality. How can I achieve this?


Solution

  • You can do the following on the Button's onClickListener if the Button and CheckBox share the same parent

    boldButton.setOnClickListener(new OnClickListener()
    {
    
        @Override
        public void onClick(View view)
        {
           View parentView = (View) view.getParent();
           CheckBox checkBox = (CheckBox) parentView.findViewById(R.id.check);
        }
    });
    

    This will give you the CheckBox corresponding to the clicked Button