vendredi 8 mai 2015

Clicking on overlapping UI elements

I have a Fragment that takes up half the activity. Behind it, a ListView. The problem is that when the user taps anywhere on the Fragmentthat overlaps with a row on the list view, the row gets clicked and it's onClick method gets called.

A workaround was giving an onClick to the LinearLayout in the Fragment layout XML file, like so :

<LinearLayout xmlns:android="http://ift.tt/nIICcg"
    xmlns:tools="http://ift.tt/LrGmb4" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.karimnseir.instabeat.IBMenuFragment"
    android:background="@color/material_blue_grey_950"
    android:onClick="doNothing">

Which I don't think is very elegant because I have to add a doNothing method to every activity that uses this fragment

If there isn't a way to stop onClicks from being called on elements BEHIND the fragment, how can I still give it a null onClick without having a dummy method everywhere ?

Thank you

Aucun commentaire:

Enregistrer un commentaire