I can not create layout inside the json request [closed]

-1

Hello

In my project, I get some fields via JSON, I have an empty layout, and I must create the elements (textview, imageview, edittext ...) according to the data received from JSON.

JSON is receiving correctly, and outside of it, I can create any layout element programmatically. The problem is that within the JSON request, where I do the "if" checks to place elements, the application stops working.

this.handler.get(nmForm, new HttpJsonObjectListener() {

        @Override
        public void onRequestCompleted(final JSONObject object, Integer httpStatus, CharSequence msg) {

            TextView t = new TextView(getBaseContext());
            t.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            t.setText("TextView");

            layout_form.addView(t);



            final JSONArray formFields = object.optJSONArray("formFields");

            for(int i = 0; i < formFields.length(); i++) {

                if(!tpRender.equals("HIDDEN")) {

                    Log.i("aanmLabel", nmLabel);
                    Log.i("tpRender", tpRender);
                    String qth = String.valueOf(qtHeight); 
                    Log.i("aaqtHeight", qth);
                    String qtw = String.valueOf(qtWidth); 
                    Log.i("aaqtWidth", qtw);

                    if(tpRender.equals("COMBO_BOX")) {
                        /*Spinner s2 = new Spinner(NewActivity.this);
                        s2.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
                        // e.setText("Button");
                        layout_form.addView(s2);*/

                    }

                }

            }
        }
    }, new HttpFailListener() {
        @Override
        public void onRequestCompleted(Exception e, Integer httpStatus, CharSequence msg) {
            Log.i("webview", "falhou ao obter json");
        }
    });

I've just placed a textview as test, and out of the check, but it does not work. Someone help me?

    
asked by anonymous 10.11.2015 / 22:33

1 answer

2

I managed to resolve. I programmatically declare the layouts within the Handler, and within

this.runOnUiThread(new Runnable() {
                        public void run() {
    
11.11.2015 / 17:28