无法在图像视图上单击

问题描述 投票:0回答:1

我正在使用android studio制作一种PDF maker应用。我试图在网格视图上显示图像,并在每个图像的顶部放置一个复选框以跟踪所选图像。但是问题是我在其上放置了一个复选框后无法在图像视图上单击。

这是我的gallery_view.xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <RelativeLayout
        android:id="@+id/gvrl"
        android:layout_width="112dp"
        android:layout_height="120dp"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true">

        <androidx.cardview.widget.CardView
            android:layout_width="110dp"
            android:layout_height="108dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            app:cardCornerRadius="3dp">

            <ImageView
                android:id="@+id/gvivs"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="?android:attr/selectableItemBackground"
                android:scaleType="centerCrop">
            </ImageView>

            <RelativeLayout
                android:id="@+id/gvrl2"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_marginLeft="1dp"
                android:layout_marginTop="2dp">

                <CheckBox
                    android:id="@+id/gvcb"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">
                </CheckBox>

            </RelativeLayout>

        </androidx.cardview.widget.CardView>

    </RelativeLayout>

</RelativeLayout>

我已使用转换视图将这个xml文件放置在每个网格视图项目上,并且一切正常,我尝试显示使用以下代码单击的网格视图项目的ID:

        grid_view1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(Import_from_gallery.this, "clicked id is " + position, Toast.LENGTH_SHORT).show();
            }
        });

但是不显示烤面包消息。当我从gallery_view.xml中删除复选框时,它将显示出来

我在这里做错了什么?感谢您的帮助。

我正在使用android studio制作一种PDF maker应用。我试图在网格视图上显示图像,并在每个图像的顶部放置一个复选框以跟踪所选图像。但是...

android imageview onclicklistener
1个回答
0
投票
android:clickable="true"
android:focusable="true"
image_view.setOnClickListener(...)

android:onClick="someMethod"
public void someMethod(View v) {
    ...
}
© www.soinside.com 2019 - 2024. All rights reserved.