【问题标题】:Listview onClick not working with overlay Framelayout androidListview onClick不适用于覆盖Framelayout android
【发布时间】:2015-02-24 08:50:35
【问题描述】:

我有一个列表视图。 ListView 的每一项都有Horizo​​ntalScrollview 和textview。水平滚动视图里面有图像。我正在使用 FrameLayout 在水平滚动视图(左侧)上显示文本视图。

我可以做到。但是当我点击 TextView 来调用 ListView 的 Long Click Listener 时,会触发 Image View 的 OnClick 事件。

这里是 ListView 项目 XML 文件。

  <?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:id="@+id/linearLayoutListViewItem"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal"
>

<HorizontalScrollView
    android:id="@+id/horizontalScrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="none"
    >

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal"
        >

        <!-- Adding images here programmatically..-->

    </LinearLayout>

</HorizontalScrollView>


<!-- Textview That i want to show on left side Above the images in         HorizontalScrollview-->
<gallery.com.activity.CustomTextView
    android:id="@+id/textview"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="#a0000000"
    android:gravity="center"
    android:padding="7dp"
    android:textSize="16dp"
    >

</gallery.com.activity.CustomTextView>

</FrameLayout>

另外,这是我的 ListView XML 文件。

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".MainActivity"
    android:orientation="vertical">

<gallery.com.activity.DynamicListView
    android:id="@+id/listView"
    android:background="#0000"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="none"

    />
</LinearLayout>

那么,我怎样才能调用 ListView 的 Long Click Listener 呢? 请帮忙。 如果您想进一步澄清这个问题,请告诉我。

【问题讨论】:

    标签: android android-layout listview


    【解决方案1】:

    你试过setOnItemLongClickListener

    YourListView.setOnItemLongClickListener(new OnItemLongClickListener() {
    
            public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                    int pos, long id) {
    
                //Whatyouwant
                return true;
            }
        }); 
    

    【讨论】:

    • 问题是当我使用 LinearLayout 而不是 FrameLayout 它的工作..
    • 得到了解决方案...在 CustomTextView 中添加 android:longClickable="true" 。
    • @RajeevKumar 完美! :) 现在也许我的代码对你有用。
    【解决方案2】:

    将 android:longClickable="true" 添加到 CustomTextView 中。

    【讨论】:

      猜你喜欢
      • 2014-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-26
      • 1970-01-01
      相关资源
      最近更新 更多