Android 未触发McClick侦听器
我使用定制的网格视图。我正在膨胀布局为belewAndroid 未触发McClick侦听器,android,xml,gridview,imageview,Android,Xml,Gridview,Imageview,我使用定制的网格视图。我正在膨胀布局为belew <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background=
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FEFAFA"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/relative_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/grid_image_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/ic_action_refresh"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false" >
</ImageView>
</RelativeLayout>
<LinearLayout
android:id="@+id/relative_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<TextView
android:id="@+id/grid_text_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall" >
</TextView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/grid_text"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/productpricefirstlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="RS 200"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#F21111" >
</TextView>
<TextView
android:id="@+id/discprice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="(50% off)"
android:textAppearance="?android:attr/textAppearanceSmall" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:orientation="vertical" >
<TextView
android:id="@+id/disc_ammount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(Rs.400)"
android:textAppearance="?android:attr/textAppearanceSmall" >
</TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp" >
<Button
android:id="@+id/shareproduct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="3dp"
android:background="@drawable/share" />
</RelativeLayout>
</LinearLayout>
那么我需要在哪里写作呢
“我的xml”中的这两行?如果列表中的任何行项目包含可聚焦或可单击的视图,则
OnItemClickListener
将无法工作
行项目必须具有类似于android:DegenantFocusability=“BlocksDescents”的参数。
在这里您可以看到示例,您的列表项应该是什么样子的
row_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical" >
// your other widgets here
</LinearLayout>
从我之前的中获得了解决方案布局中没有网格视图为什么要为ImageView提供这些属性:“android:clickable=“false”和android:focusable=“false”" ? 另外,您是否在适配器中为该ImageView提供了onClickListener?您好,blueware,我已经编写了这些行来聚焦网格视图,以从图像视图中移除焦点。我可以在适配器类中为图像视图打开click listener,但我不想要那个。我需要在网格视图点击侦听器。嗨,Kartheek谢谢,它为我做了一半。我对每个小部件都尝试了上面的代码,但它只对较低的部分起作用。较低的部分意味着什么?这一部分将focusable和focusableInTouchMode添加到视图(按钮和文本视图)中。Kartheek仍然没有运气图像阻止单击:(。
"android:clickable="false"
android:focusable="false""
row_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical" >
// your other widgets here
</LinearLayout>
android:focusable="false"
android:focusableInTouchMode="false"