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>
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