M
M
Max2017-04-29 19:06:46
Android
Max, 2017-04-29 19:06:46

How to programmatically add elements?

Dear. Need advice. I will extract information from sql and I need to programmatically add elements, it all depends on the database (that is, the number of elements created and their name.) They still need to be assigned an id and by clicking on this element, transfer information to another activation. For example, I have a table in the database with free time, and I need buttons with the name of this time to be created on the screen and it to be active. That's the question, how best to create using a button or through a list.? And how to assign an id to them? After all, I don’t know in advance how many there will be.
2a26c85fb8ba45c7bbb491fe3ac49e02.jpg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mitaichik, 2017-04-29
@mitaichik

How to pull it out of the database is written in the docks https://developer.android.com/training/basics/data...
You can either create a new Button directly and then set all the parameters, or better with inflate (allows you to create a normal layout in xml) .
You don't need to assign an id, you need to put setOnClickLisener on the buttons.
Use sheets - xs, perhaps, depending on how many of these buttons there will be and what needs to be done with them.

D
Dmitry Serkov, 2017-05-02
@Hutaab

It is possible through RecyclerView

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question