0

I have frameLayout which has two views. This frameLayout inside another frame and relativeLayout.

I want to add ImageView click and long click listeners. When I click ImageView, set ImageButton touchListener.

I add clickable, focusable, longClickable and android:descendantFocusability but it does not even get into these parts of the ImageView's listeners.

Please help me

  ImageView imageView = (ImageView) findViewById(R.id.view1);
  ImageButton imageButton = (ImageButton) findViewById(R.id.button);

   imageView.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {

            button.touchableButton(true);
            return true;
        }
    });

    imageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            button.touchableButton(false);

        }
    });

    public void touchableButton(boolean touchable) {
     imageButton.setOnTouchListener(touchable ? this : null);
    }

My layout:

<RelativeLayout
        android:id="@+id/grandPaRelative"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

    <FrameLayout
        android:id="@+id/dadFrame"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:clipChildren="false"
        android:clipToPadding="false">

                         <FrameLayout
                            android:id="@+id/momFrame"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:clipChildren="false"
                            android:clipToPadding="false"
                            android:descendantFocusability="blocksDescendants">

                            <ImageButton
                                android:id="@+id/button"
                                android:layout_width="48dp"
                                android:layout_height="48dp"
                                android:layout_gravity="center"
                                android:layout_marginTop="5dp"
                                android:adjustViewBounds="true"
                                android:background="@drawable/circle_tintable"
                                android:contentDescription="@null"
                                android:gravity="center"
                                android:padding="10dp"
                                android:src="@drawable/abc" />

                            <ImageView
                                android:id="@+id/view1"
                                android:layout_width="48dp"
                                android:layout_height="48dp"
                                android:layout_gravity="center"
                                android:layout_marginTop="5dp"
                                android:adjustViewBounds="true"
                                android:clickable="true"
                                android:contentDescription="@null"
                                android:focusable="true"
                                android:gravity="center"
                                android:longClickable="true"
                                android:padding="15dp"
                                android:visibility="gone"
                                app:circleColor="@color/topBar" />

                    </FrameLayout>

         <ImageView
            android:id="@+id/view2"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_gravity="center"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:contentDescription="@null"
            android:gravity="center"
            android:padding="15dp"
            android:src="@drawable/view2"
            app:circleColor="@color/topBar" />

          </FrameLayout>
</RelativeLayout>
propoLis
  • 1,229
  • 1
  • 14
  • 48

2 Answers2

1

try with return true to false. ImageView imageView = (ImageView) findViewById(R.id.view1); ImageButton imageButton = (ImageButton) findViewById(R.id.button); imageView.setOnLongClickListener(new OnLongClickListener() {

    @Override
    public boolean onLongClick(View view) {

        button.touchableButton(true);
        return false;
    }
});`
Durgesh Kumar
  • 935
  • 10
  • 17
0

I have heard of people's images being hidden behind Frame Layouts before and that prevents the imageView from clicking. I might try deleting android:visibility="gone" and seeing if that fixes things. If not this thread might help: Android ImageView's onClickListener does not work

propoLis
  • 1,229
  • 1
  • 14
  • 48
  • Ah yes you do! Have you tried putting the click listener before the long click listener? – Matthew Flathers Jan 16 '18 at 16:59
  • it doesn't matter – propoLis Jan 16 '18 at 17:08
  • Well it appears as if you made view1 clickable and longclickable but I don't see those declarations for your view2. And view2 is the one you are trying to set the listeners on. – Matthew Flathers Jan 16 '18 at 17:12
  • Hmmmm then I don't see anything wrong in your code. It seems like for some reason your imagviews never register as clicked – Matthew Flathers Jan 16 '18 at 17:24
  • 1
    I have heard of people's images being hidden behind Frame Layouts before and that prevents the imageView from clicking. I might try deleting android:visibility="gone" and seeing if that fixes things. If not this thread might help: [Android ImageView's onClickListener does not work ](https://stackoverflow.com/a/6083930/9220124) – Matthew Flathers Jan 16 '18 at 17:35