Question on ListView in Android?

Hello)


My android application has an activity to display results of search of music.

(above is a box for music, and below the results list).


I will first list of results was done using tables (placed in a TableView TableRow).

But this option was not the best, because the line is not highlighted when you click, and the mechanism of populating this table was quite difficult and not optimal).


Then I stumbled upon such a thing as a ListView.

I started googling, and realized that this option is much more suitable than table.


But from the examples and docs I did not understand some things, and so I ask you to help me.


What I need to do:


I need a ListView that will element in LinearLayout.

I also need a mechanism to populate this element with a text and two buttons (horizontal)

And the treatment of depression on each of them.


(There is a Sound object that contains the name of the song and a link to it)


If someone explain I'd be very grateful =)
October 8th 19 at 03:52
2 answers
October 8th 19 at 03:54
To explain in detail for a long time, but it is necessary to look towards something like ArrayAdapter (or CursorAdapter — it depends where the data for the list come from). Written a separate xml for the list item, then the adapter for each element creates the appropriate View and populates it with data. Keywords for search examples: ListView, ArrayAdapter, getView (this is the adapter method which should be overridden).

With the buttons in the list item, like, too, was some kind of trick, but can't remember now. Like, it was necessary to set the properties of the list item that was pressed it buttons, not the entire element at once.
Oh, I forgot to say: the adapter is given in the ListView and that he jerks need adapter methods for drawing elements. - Aric commented on October 8th 19 at 03:57
SPS, and pressing the buttons inside the list as table? - tiara_Padbe commented on October 8th 19 at 04:00
There may be two tricks. First, under some conditions, can press the entire element — something connected with the focus, I think. How to overcome I do not remember, but Google is full of answers. Secondly, you will need when you expand element (in method getView) to assign to each button handler. And the handler needs to be able to determine which button is pressed. I probably would have used the Tag field — set back to the same Sound.

In General, it is so common task that Google gives a bunch of examples with code and explanations. Look. - Aric commented on October 8th 19 at 04:03
October 8th 19 at 03:56

Find more questions by tags AlgorithmsJavaProgrammingAndroid