Im having some problem with Click Listener on Image View
I try to log some text if I click on the button
But it not work at all
Here is my code, Hope u can help me:
ChatHeadService.java
ImageView closeButton = (ImageView) mChatHeadView.findViewById(R.id.close_btn);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("myTag", "This is my message");
//close the service and remove the chat head from the window
stopSelf();
}
});
Layout_chat_head.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="65dp"
android:id="@+id/chat_head_root"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--Profile image for the chat head.-->
<ImageView
android:id="@+id/chat_head_profile_iv"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginTop="8dp"
android:src="@drawable/icon_128"
tools:ignore="ContentDescription" />
<!--Close button-->
<ImageView
android:id="@+id/close_btn"
android:layout_width="26dp"
android:layout_height="26dp"
android:layout_marginLeft="40dp"
android:src="@drawable/close"
tools:ignore="ContentDescription" />
</RelativeLayout>
[EDIT] Here is the image of the layout:
P/s: I had read the similar problem in here: Android ImageView's onClickListener does not work
But it seem not work for me.