5

I'm working on expandable list view. I've set onClickHandler on imageview of the child row, because inline clicklistners not working in this case. But I need int groupPosition and childPosition for some processing in my program. And these are available from OnChildClick().

The problem is I need OnclickHandler and OnChildClick() (for groupPosition and ChildPosition) both. Is there anyway to get these two values? can we call (invoke) OnChildClick method manually?

public class ExpList extends ExpandableListActivity
  {
       /** Called when the activity is first created. */
         @Override
         public void onCreate(Bundle icicle)
          {
            super.onCreate(icicle);
            setContentView(R.layout.main);

            getExpandableListView().setOnChildClickListener(new OnChildClickListener() 
            {
                public boolean onChildClick(ExpandableListView parent, View v,int groupPosition, int childPosition, long id) 
                {
                     // some calculations here....
                     return false;
                }
            });
  }


public void onClickHandler (View v) 
 {
     switch (v.getId()) {
         case R.id.imgcall:     

            //Here I need groupPosition and ChildPosition....

                 my_function();
                 break;        

         case R.id.img_call_icon:

                 // some code here......                    
                break;
            }               
     }
 }

My child_row.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView 
        android:id="@+id/img_call_type"

        android:layout_width="40px"
        android:layout_height="40px"/>

         <TextView 
         android:id="@+id/space"                   
         android:layout_width="10px"
         android:layout_height="wrap_content"/>

    </LinearLayout>

    <LinearLayout 
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView 
             android:id="@+id/name"         
             android:textSize="14px"             
             android:layout_width="115px"
             android:layout_height="wrap_content"/>

        <TextView
             android:id="@+id/number"
             android:textSize="14px"             
             android:layout_width="115px"
             android:layout_height="wrap_content"/>

    </LinearLayout>

    <LinearLayout 
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView 
             android:id="@+id/date"         
             android:textSize="14px"          
             android:layout_width="115px"
             android:layout_height="wrap_content"
             />

        <TextView 
             android:id="@+id/time"
             android:textSize="14px"         
             android:layout_width="115px"
             android:layout_height="wrap_content"
            />        

    </LinearLayout>

     <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">



<!-- on this imageview i put OnClickHandler -->    

            <ImageView 
            android:id="@+id/img_call_icon"

        android:layout_width="40px"
        android:layout_height="40px"
        android:clickable="true"
        android:onClick="onClickHandler"/>

    </LinearLayout>

</LinearLayout>
Never Quit
  • 2,072
  • 1
  • 21
  • 44

1 Answers1

-1

You can get Button Clicks on your child Click listner. In Short just copy paste your switch case statement of 'onClickHandler' to 'onChildClick'.

So, your code will be,

public class ExpList extends ExpandableListActivity
  {
       /** Called when the activity is first created. */
         @Override
     public void onCreate(Bundle icicle)
      {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        getExpandableListView().setOnChildClickListener(new OnChildClickListener() 
        {
            public boolean onChildClick(ExpandableListView parent, View v,int groupPosition, int childPosition, long id) 
            {
                 switch (v.getId()) {
     case R.id.imgcall:     

        //Here I need groupPosition and ChildPosition....

             my_function();
             break;        

     case R.id.img_call_icon:

             // some code here......                    
            break;
        }               
     }
            }
        });
  }

Don't forget to mark this as Answer if its helpful to you..

Parthraj
  • 573
  • 5
  • 16