-2

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: enter image description here

P/s: I had read the similar problem in here: Android ImageView's onClickListener does not work

But it seem not work for me.

Bao Dinh
  • 64
  • 6

4 Answers4

0

I faced this same problem. ImageView may be hidden / in background by some other view. Use some elevation
android:elevation="3dp"

Abu Saeed
  • 1,020
  • 8
  • 21
0

It simple than i thought

I just change from this:

final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                LAYOUT_FLAG,
                WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);

to this:

final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                LAYOUT_FLAG,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, //<-- Right here :)
                PixelFormat.TRANSLUCENT);
Bao Dinh
  • 64
  • 6
  • 3
    you never posted this in your original post so you made it impossible for anyone to really answer you. best to include ALL relevant detail in your posts, enough that people can actually recreate the problem – a_local_nobody Dec 23 '21 at 11:05
  • ok, I think that information is don't need to solve this problem. However, I'll learn from it next time. Thanks for your comment – Bao Dinh Dec 23 '21 at 13:45
0

In my opinion, this is not OnClickListener issue. Just put all codes of stopSelf inside of Handler(Looper.getMainLooper()).run{} then try.

0

Try reinstalling the app. Check for errors in logcat for operation bot permitted.

Claudiu Haidu
  • 817
  • 4
  • 12
  • 24