Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
        }
    }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Dynamically #bind #layouts #android #json #array
ADD COMMENT
Topic
Name
9+4 =