M
M
mrgrigo2018-09-16 23:53:03
Java
mrgrigo, 2018-09-16 23:53:03

How can output be organized?

Hello. I have some JSON array.
During its Parsing, several Linear-Layouts are programmatically created (to be precise: they are loaded from a pre-created record.xml template), several elements (title, text, buttons) are also loaded inside the Linear-Layout.
This generated LinearLayout is then fed to the "parent" LinearLayout via AddView(). Question:
How can you handle clicking on buttons in programmatically created (loaded) elements?
Those. a person presses "Remove", and a request is sent to the server with the record ID. So, how can I pull out this ID if, say, I place it in advance in some TextView (invisible), which is located in the same formed Linear Layout as the button that was pressed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
Zwieback, 2018-09-17
@Zwieback

TextView and Button must have id. Find the components by the specified id using the findViewById method, add a setOnClickListener for the button, in which you will find out the desired ID from the text: textView.getText().toString()

E
Eugene, 2018-09-17
@klim76

How can you handle clicking on buttons in programmatically created (loaded) elements?

for each button you create, add a Tag (setTag(...)) with some meaningful key and a click listener setClickListner().
Then in handling the click event see View Tag

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question