0

I've set up a ListView and assigned a custom layout to make the ListView items better looking. However, I'm looking for a way to add a button that would appear with each element in it's top right corner, like Youtube's videos: they all have that little options button with things like add to, share, etc. The problem is that you cant put a widget inside of a widget, at least I don't know a way to do it. The custom layout contains a TextView which gives the ListView items the looks. Can someone suggest a way on how should I approach this?

rtruszk
  • 3,902
  • 13
  • 36
  • 53
Richard
  • 121
  • 10
  • please post some of your work regarding this matter, and post an image that show how do you want the layout to look like – Ahmad Sanie Apr 19 '15 at 14:03

2 Answers2

0

Use FrameLayout for your custom ListView items. like this:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
    <TextView
     android:id="@+id/tvText"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_gravity="center"
     />

    <Button android:id="@+id/button"
    android:layout_width="22dp"
    android:layout_height="22dp"
    android:layout_gravity="top|right"
        />
</FrameLayout>

NB - when widgets overlaps in layout, last written widget will be topmost.

Raiv
  • 5,731
  • 1
  • 33
  • 51
  • Well, this works, sorta. As you mentioned the last written widget is the topmost, could this be the problem why my onItemClickListener i've set up for the listView items is not working? – Richard Apr 19 '15 at 15:25
  • yes, it could. also make sure you are not blocking clicks on your listener. to check it, add android:descendantFocusability="afterDescendants" in your listViewItems – Raiv Apr 19 '15 at 15:44
0

Here is a link where you will find what you want. It shows you how to add button in list view.

You will need to change some XML code and adjust the onClickListeners but it's similar to what you are looking for.

Community
  • 1
  • 1
Arthur Lemoine
  • 200
  • 3
  • 9