There is an ExpandableListView with a custom adapter: For Child:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="2dp" android:layout_marginTop="2dp" android:background="@drawable/border_one_task" android:orientation="horizontal" > <CheckBox android:id="@+id/checkbox_task" android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="center_vertical" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/textview_task_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="2dp" android:layout_marginLeft="2dp" android:layout_marginTop="2dp" android:gravity="left" android:text="Задача1" android:textAppearance="?android:attr/textAppearanceLarge" /> <LinearLayout android:layout_width="match_parent" android:layout_height="28sp" android:layout_marginBottom="2dp" > <TextView android:id="@+id/textview_task_date" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginRight="4dp" android:gravity="center_vertical" android:text="10.12.2014" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="#0000ff" /> <ImageView android:id="@+id/imageview_task_map" android:layout_width="25sp" android:layout_height="25sp" android:src=" @android :drawable/ic_menu_mapmode" /> </LinearLayout> </LinearLayout> </LinearLayout> </LinearLayout> 

It is necessary to handle the event of clicking on the CheckBox. At the same time it is necessary to call the method from the caller of activation (To refresh the data). How can this be done?

  • @Lucky_spirit everything turned out) thanks :) - Maria_1
  • I can make it an answer, and you mark it as accepted. - Lucky_spirit

2 answers 2

Create an Interface and declare a method in it. Activity force the implementation of this Interface. In the adapter's constructor for this ListView, add the Interface parameter that you created, and when creating this adapter, pass this Activity, which implements this interface. Save it as a class field. When clicking on CheckBox, call the method of this interface, the method will be called by the Activity. This is a simple example of a callback implementation.

Another option through Context. Not sure if it is correct.

 if (context instanceof MyActivity) { ((MyActivity) context).my_method(); } 
  • it didn't work out) - Maria_1
  • The method in the activation should be public. The context should be of the form MyActivity.this, not getApplicationContext (). So it should turn out. It is so difficult to determine the cause of what did not work out exactly without seeing the full code. - otr23
  • @ otr23 I agree. But, fortunately, it turned out the first method) - Maria_1