I would like to implement a ListView, which I can do no problem w/ my cursor. Right now depending on which row you click on it takes you to a new activity based on the information pressed on that row (just like it should, and as expected). I would like to have a button however to delete the row, so a user can press any part of the row to launch the new activity, but if they press the button on that row, it deletes the row (or launches a delete activity/function).
If you can look @ DroidRecord, they have a similar layout as I am looking to achive.
Thanks!
Chris.
As Mariano Kamp said, adding buttons to a row will make it "untouchable", but in my experience, this problem goes away if you set these properties on the buttons:
android:focusable="false"
android:focusableInTouchMode="false"
See also How to fire onListItemClick in Listactivity with buttons in list?
Another possible workaround - you can use an ImageView instead of the button, and set the ImageView's onClickListener (For example, when you're inflating the cell view).
ImageView is not focusable so it doesn't prevent OnListItemClick() from being dispatched, and when you click on the image only the image's listener fires.
what is your question? How to add a button to a list row?
Very simple, just as you expect it will be added to the row's layout.
Unfortunately though that will also make the whole row "untouchable". The Google developer I asked said that this is by design (as far as I remember), and that you should use TouchDelegate to cope with this. As there are no samples, not even in the android source, and only very thin documentation that didn't work for me
Anyway, it seems that not many applications use a button in the list row. I only know about mine (newsrob, see Articles List) and the Alarm clock. Maybe you could use a context menu?
Otherwise the ugly solution would be to add to call setOnClickListener() on your row view in the getView method.
Cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With