开发者

Create dynamic view with android

开发者 https://www.devze.com 2022-12-28 06:36 出处:网络
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 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 a开发者_JS百科n 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...


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号