Answers for "Dynamically bind layouts android with json array"

0

Dynamically bind layouts android with json array

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
        }
    }
Posted by: Guest on June-10-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language