T
T
trollface2012-01-20 21:00:51
Java
trollface, 2012-01-20 21:00:51

Question on ListView in Android?

Hello everyone)
I have an activity in my android application to display music search results.
(At the top is the field for music, and at the bottom is the list of results).
First, I made a list of results using a table (I placed a TableRow in the TableView).
But this option turned out to be far from the best, because. the row was not highlighted when pressed, and the mechanism for filling this table was rather complicated and not optimal).
Then I came across such concept as ListView.
I started googling, and realized that this option is much more suitable than a table.
But from examples and docks, I did not understand some things, and therefore I ask you to help me.
What I need to do:
I need a ListView to be an element in a LinearLayout.
And also I need a mechanism to fill this element with text and two buttons (horizontally)
AND handle clicking on each of them.
(There is a Sound object containing the name of the song and a link to it)
If someone explains this to me, I will be very grateful =)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Grichenko, 2012-01-20
@Kalobok

It takes a long time to explain in detail, but you need to look in the direction of something like ArrayAdapter (or CursorAdapter - depending on where the data for the list comes from). A separate xml is written for the list element, then the adapter creates the corresponding View for each element and fills it with data. Keywords to search for examples: ListView, ArrayAdapter, getView (this is the adapter method that needs to be overloaded).
With the buttons in the list element, it seems, there was also some kind of trick, but I don’t remember the details now. It seems that it was necessary to somehow set the properties of the list and the element correctly so that the buttons were pressed, and not the entire element at once.

M
Martivic, 2014-07-27
@Martivic

I recommend to study what you are dealing with: startandroid.ru/ru/uroki/vse-uroki-spiskom.html
Directly the topic of your question:
startandroid.ru/ru/uroki/vse-uroki-spiskom/82-urok...
startandroid.ru/ru/uroki/vse-uroki-spiskom/113-uro...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question