Create dynamic view with android
android, android-activity, json, widget
Solution
When you are generating the widget programmatically, you can assign them your own id.
For example:
Button btn = new Button(this);
btn.setId(myBtnId);
And later in your code, you can reference to that button with `findViewById(myBtnId)`.
Problem
I'm stuck on a problem and if possible I will need help from the community. I'm not looking for a ready-made solution, but something which would help me to produce the result. I'm looking for a way to produce a dynamic activity based on a JSONArray object. Here an example of a JSONArray object: ``` [ { "name": "my checkbox name", "type": "checkbox", "value": "one,two,three" } { "name": "my edit text", "type": "text", "value": "" } ...] ``` This JSONArray could be totally random. It could have 2 text views, 3 select menus, 1 text view and so on. The goal is to iterate over this JSONArray and create the appropriate elements within my android code. To produce the result I've thought of a simple switch which would render one by one my different JSONArray to an android widget. But after that how could I have access of every property of every widget rendered? Edit: I need as well to assign an event listener on some widget as taking the GPS coordinated... Thank you. Edit: this is a JSONArray not a JSONObject...