Note that there are some explanatory texts on larger screens.

plurals
  1. POset onLongClick for a gridview in Android
    text
    copied!<p>I want to set <code>onLongClickListener</code> for a <code>gridview</code> and only want the <code>onLongClick()</code> method to be invoked when the user long presses on an empty space of the gridview. I am also using an <code>onItemLongClickListener</code> for the items of the gridView which works fine.</p> <p>I have tried putting a <code>view</code> and the <code>gridview</code> within a <code>framelayout</code> with equal width and height(<code>view's</code> height is set programmatically to match that of the <code>gridview</code>) but the <code>onClick()</code> only works for the view which is on top(declared first in the frame layout).</p> <p>Is there any way i can set <code>onLongClickListenter</code> for a <code>gridView</code>? I need both <code>onLongClick()</code> and <code>onItemLongClick()</code> to work.</p> <p>Here is my <code>xml layout</code>:</p> <pre><code>&lt;RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;FrameLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_above="@+id/taskBar" android:layout_alignParentTop="true"&gt; &lt;View android:id="@+id/gridViewOnClickArea" android:layout_width="match_parent" android:layout_height="wrap_content"&gt; &lt;/View&gt; &lt;fragment android:id="@+id/fragment1" android:name="com.example.androidfilemanager.DirectoryFragment" android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;/fragment&gt; &lt;/FrameLayout&gt; &lt;HorizontalScrollView android:id="@+id/taskBar" android:layout_width="match_parent" android:layout_height="50dip" android:layout_gravity="bottom" android:layout_alignParentBottom="true" android:background="@android:color/background_dark"&gt; &lt;LinearLayout android:id="@+id/taskbarLinearLayout" android:layout_height="50dip" android:layout_width="wrap_content" android:orientation="horizontal"&gt; &lt;Button android:id="@+id/homeButton" android:layout_width="wrap_content" android:layout_height="50dip" android:text="@string/home" android:background="@drawable/taskbar_item" android:textColor="@android:color/white"/&gt; &lt;View android:layout_width="2.5dip" android:layout_height="match_parent" android:background="#001d27"/&gt; &lt;/LinearLayout&gt; &lt;/HorizontalScrollView&gt; &lt;/RelativeLayout&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload