Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

android - Floating Action Button does not responds when it clicked/touched

I am using a floating action button(FAB) in my application to show Dialogs, everything is worked just fine when I tested my app in Xperia Z with Lopllipop 5.1.1.
However, the problem is when tested my app in ASUS Zenfone 6 with KitKat 4.4.2 and in Xperia C with Jelly Bean 4.2.2, the FAB loaded perfectly but the FAB does not show the Dialogs, seems like it does not responds when I touched it.
For the record, my min sdk version is 16.

What i want to ask is why this is happening? Is there anything wrong with my code, or maybe with the android version or API level?

Please take a look at my code. Here the XML code:

    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/ic_add_account"
    android:visibility="invisible"
    android:clickable="true"/>

and here how I declare and set the listener for the FAB:

FloatingActionButton fab;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

   fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);

   ...
   fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showDialog();
            }
   });
   ...
}

The thing that made me confused is how it is worked in Xperia Z but it does not worked in ASUS Zenfone 6?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The problem in here is that I declared the FAB before the declaration of listView. Somehow by relocating the declaration of FAB after the the declaration of listView it will solved the problem.
From:

<android.support.design.widget.FloatingActionButton
    ...
    ...
    .../>
<ListView
    ...
    ...
    .../>

To:

<ListView
    ...
    ...
    .../>
<android.support.design.widget.FloatingActionButton
    ...
    ...
    .../>

Just as simple as that.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...