📜  使用 json 数组动态绑定布局 android - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:31.254000             🧑  作者: Mango

代码示例1
JSONArray jArray = jObject.getJSONArray("layout");
    layout = (LinearLayout) findViewById(R.id.statsviewlayout);

    for (int i=0; i < jArray.length(); i++)
    {
        try {
            JSONObject oneObject = jArray.getJSONObject(i);
            // Pulling items from the array
            String tag = oneObject.getString("tag");
            String name= oneObject.getString("name");
            String hint= oneObject.getString("hint");
            Button button = new Button(this);
            button.setText(name);
            button.setLayoutParams(new LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        layout.addView(buyButton);

        } catch (JSONException e) {
            // Oops
        }
    }