Creating a dynamic view using android

I am stuck in a problem and, if possible, I will need the help of the community. I am not looking for a turnkey solution, but something that will help me create the result.

I am looking for a way to create dynamic activity based on a JSONArray object. Here is an example JSONArray object:

[ { "name": "my checkbox name",
    "type": "checkbox",
    "value": "one,two,three"
  }
  { "name": "my edit text",
    "type": "text",
    "value": ""
  }
  ...]

This JSONArray can be completely random. It can have 2 text views, 3 selection menus, 1 text view, etc.

The goal is to iterate over this JSONArray and create the appropriate elements in my Android code.

To create the result, I thought of a simple switch that will display my JSONArray for the Android widget one by one.

But after that, how can I access each property of each widget?

: - , GPS ...

.

: JSONArray, JSONObject...

+3
1

, .

:

Button btn = new Button(this);
btn.setId(myBtnId);

findViewById(myBtnId).

+3

Source: https://habr.com/ru/post/1742661/


All Articles