-2

How to add a floating button on ListFragment? (listAdapter..) I saw lots of examples using activity but none substancial using ListFragments.. Is it even possible?

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
BVtp
  • 2,308
  • 2
  • 29
  • 68
  • I think you are being downvoted for lack of research effort. There is nothing fundamentally different about adding something to an activity or a fragment. If you are confused about `onCreateView`, then you should look up a tutorial: http://developer.android.com/training/basics/fragments/creating.html#Create. – tachyonflux Jul 13 '15 at 17:17

1 Answers1

0

You need to override onCreateView in your Fragment class.

http://developer.android.com/reference/android/app/ListFragment.html

ListFragment has a default layout that consists of a single list view. However, if you desire, you can customize the fragment layout by returning your own view hierarchy from onCreateView(LayoutInflater, ViewGroup, Bundle). To do this, your view hierarchy must contain a ListView object with the id "@android:id/list" (or list if it's in code)

Create your own layout with a Frame or Relative layout that allow views to overlap - and make your floating button.

Roughly like this:

<FrameLayout>
   <ListView android:id="@id/android:list" />
   <Button />
</FrameLayout>
Raanan
  • 4,777
  • 27
  • 47
  • 1
    When I tried that my app crashed.. Do you happen to know by any chance where I can see an example code implementing this kind of thing? Thank you. – BVtp Jul 13 '15 at 16:01
  • In your layout did you give your listview this id: "@android:id/list" ? The fragment is expecting this. – Raanan Jul 13 '15 at 16:02
  • please post your onCreateView code, that would help. – Raanan Jul 13 '15 at 16:04