i'm developing android messaging application using java when a receive a message i inserted the information of it to a database.. i want to create a listview with dynamic buttons, each button contain the data in the row of the database and i need to connect the id of the button to the id of the record so i can apply changes to the buttons such as deleting it using the id of it, and i need to create a new button every time i receive a message. I've been searching for some answers but i didn't find anything like this.. thanks in advance.
Your button doesn't really need to be dynamic, you can load a <Button>
from an XML layout which describes your ListView
row. Then, in your ListView
adapters getView() method
, use Button.setTag()
to put a tag object on the button, set a title on the button, etc ... this tag object could simply reference your database row _ID
.
Use Button.getTag()
in the button onClick()
handler to read the _ID
and do what you need.
Use a DataSetObserver
on your adapter. Call notifyDataSetChanged()
on your adapter when you receive this message to force the ListView
to update itself.