0

i have a main layout, called doit_service_expandablelistview, and I include a second layout, called doit_service_list_group, into the main layout. The second layout contains an ImageButton. I now want to call an onClick Event on the ImageButton. I do this in the activity where the main layout is inflated.

This is how I inflate the main layout:

  LayoutInflater factory = LayoutInflater.from(getParentActivity());
  v = factory.inflate(R.layout.doit_service_expandablelistview, null);

And this is how I inflate the second layout:

  View doitGroupLayout = fragmentView.findViewById(R.id.doitGroupView);
        ImageButton editService = (ImageButton) doitGroupLayout.findViewById(R.id.edit_service);

        editService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("on edit click: ", "test");

            }
        });

This is the include tag inside of the main layout:

   <include layout="@layout/doit_service_list_group"
    android:id="@+id/doitGroupView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"/>

This is my problem: The onClick Event doesn't fire, meaning I don't get the log

Log.d("on edit click: ", "test");

in my logcat output

Can anyone please help me figure out what the problem is here. Thanks in advance.

EDIT: doit_service_list_group.layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants">

<ImageView
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:id="@+id/orgPic"
    android:background="#f2f2f2"
    android:layout_marginTop="15dp"
    android:layout_marginLeft="15dp"
    android:layout_marginBottom="15dp"
    android:layout_marginRight="30dp"
   />



<TextView
    android:id="@+id/serviceId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="15dp"
    android:textColor="#00aeef"
    android:textStyle="bold"
    android:layout_below="@+id/orgPic"
    android:layout_alignLeft="@+id/orgPic"
    android:layout_marginBottom="5dp"/>


<TextView
    android:id="@+id/serviceName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="18dp"
    android:singleLine="true"
    android:textColor="#00aeef"
    android:layout_marginBottom="10dp"
    android:layout_marginRight="15dp"
    android:layout_toRightOf="@+id/orgPic"
    android:layout_alignTop="@+id/orgPic"
    android:includeFontPadding="false"
    android:layout_toLeftOf="@+id/edit_service"
    android:layout_toStartOf="@+id/edit_service" />

<TextView
    android:id="@+id/creationDate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="12dp"
    android:textColor="#818181"
    android:layout_below="@+id/orgPic"
    android:layout_alignLeft="@+id/orgPic"
   />

<TextView
    android:id="@+id/serviceDescription"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="15dp"
    android:layout_marginBottom="15dp"
    android:layout_marginRight="15dp"
    android:textColor="#818181"
    android:lines = "2"
    android:maxLines="2"
    android:ellipsize="end"
    android:layout_below="@+id/serviceName"
    android:layout_alignLeft="@+id/serviceName"
    />

<TextView
    android:id="@+id/creationDateExpanded"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="12dp"
    android:textColor="#818181"
    android:layout_below="@+id/serviceId"
    android:layout_alignLeft="@+id/orgPic"
    android:layout_marginBottom="5dp"
    />

<TextView
    android:id="@+id/supplier"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="15dp"
    android:paddingBottom="5dp"
    android:paddingLeft="10dp"
    android:singleLine="true"
    android:textColor="#818181"
    android:layout_below="@+id/creationDateExpanded"
    />

<TextView
    android:id="@+id/customer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="15dp"
    android:paddingBottom="5dp"
    android:paddingLeft="10dp"
    android:singleLine="true"
    android:textColor="#818181"
    android:layout_below="@+id/supplier"
    />

<TextView
    android:id="@+id/divider"
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:background="#CCCCCC"
    android:layout_below="@+id/creationDate"
    android:layout_marginTop="15dp"
    />

<ImageButton
    android:id="@+id/edit_service"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_ab_search_grey"
    android:text="Button"
    android:clickable="true"
    android:layout_marginTop="15dp"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="15dp"
    android:background="?android:attr/selectableItemBackground"

    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    /></RelativeLayout>

0 Answers0