Android - TextView - getText devueve null - URGENTE

 
Vista:
Imágen de perfil de Carl

TextView - getText devueve null - URGENTE

Publicado por Carl (7 intervenciones) el 14/11/2015 03:12:14
Hola Tengo el sigueinte codigo. pero el problema es que en onCreateView vuelve nulos mis variables, plz ayudenme


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
public class FragmentProjectActivity  extends Fragment {
    String myJSON;
 
    private static final String TAG_RESULTS = "result";
    private static final String TAG_CLICODE = "cli_code";
    private static final String TAG_CLIBUSINESSNAME = "cli_business_name";
    private static final String TAG_CLIRUC = "cli_ruc";
    private static final String TAG_CLIREPRESENTATIVE = "cli_representative";
    private static final String TAG_CLIADDRESS = "cli_address";
    private static final String TAG_CLICOMPANYEMAIL = "cli_compañy_email";
    private static final String TAG_CLIPHONE = "cli_phone";
    private static final String TAG_CLICELLPHONE = "cli_cell_phone";
    private static final String TAG_CLISTATE = "cli_state";
    JSONArray jsonArray = null;
    ArrayList<HashMap<String, String>> arrayList;
    ListView listView;
    public static String ipro_name, icli_code, clibusinessname, cliruc;
    private TextView tviProName, tvCliBusinessName, tvCliRuc;
 
    public FragmentProjectActivity() {
        // Required empty public constructor
    }
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String ipro_code=((UiProjectActivity)getActivity()).ipro_code;
        String ipro_name=((UiProjectActivity)getActivity()).ipro_name;
        String icli_code=((UiProjectActivity)getActivity()).icli_code;
        Toast.makeText(getActivity(), "INTENT ALCANZANDOS : codigo producto :"+ipro_code + "codigo cliente "+icli_code, Toast.LENGTH_SHORT).show();
        getData(icli_code);
 
    }
    protected void data() {
        final JSONObject jsonObj;
        try {
            jsonObj = new JSONObject(myJSON);
            jsonArray = jsonObj.getJSONArray(TAG_RESULTS);
            JSONObject c = jsonArray.getJSONObject(0);
            String clicode = c.getString(TAG_CLICODE).toString();
            String clibusinessname = c.getString(TAG_CLIBUSINESSNAME).toString();
            String cliruc = c.getString(TAG_CLIRUC).toString();
            String clirepresentative = c.getString(TAG_CLIREPRESENTATIVE).toString();
            String cliaddress = c.getString(TAG_CLIADDRESS).toString();
            String clicompanyemail = c.getString(TAG_CLICOMPANYEMAIL).toString();
            String cliphone = c.getString(TAG_CLIPHONE).toString();
            String clicellphone = c.getString(TAG_CLICELLPHONE).toString();
            //String clistate = c.getString(TAG_CLISTATE).toString();
            Toast.makeText(getActivity(), "RESULTADO ARREGLO: : " + clibusinessname + " yyyyy" + cliruc, Toast.LENGTH_SHORT).show();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
 
 
    public void getData(final String icli_code) {
        class GetDataJSON extends AsyncTask<String, Void, String> {
            @Override
            protected String doInBackground(String... params) {
                DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
                HttpPost httppost = new HttpPost("http://192.168.1.41:8080/MyProjects/android/AndroidProject/dao/client.php?cli_code=" + icli_code);
                // Depends on your web service
                httppost.setHeader("Content-type", "application/json");
                InputStream inputStream = null;
                String result = null;
                try {
                    HttpResponse response = httpclient.execute(httppost);
                    HttpEntity entity = response.getEntity();
 
                    inputStream = entity.getContent();
                    // json is UTF-8 by default
                    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
                    StringBuilder sb = new StringBuilder();
 
                    String line = null;
                    while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                    }
                    result = sb.toString();
                } catch (Exception e) {
                    // Oops
                } finally {
                    try {
                        if (inputStream != null) inputStream.close();
                    } catch (Exception squish) {
                    }
                }
                return result;
            }
 
            @Override
            protected void onPostExecute(String result) {
                myJSON = result;
                Toast.makeText(getActivity(), "JSON: "+myJSON, Toast.LENGTH_SHORT).show();
                data();
 
            }
        }
        GetDataJSON g = new GetDataJSON();
        g.execute();
 
    }
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_project,container,false);
 
        Toast.makeText(getActivity(), "TextEdit : " + String.valueOf(clibusinessname) + " --" + cliruc, Toast.LENGTH_SHORT).show();
        // use view instead of getView()
        TextView text = (TextView) view.findViewById(R.id.codigo);
 
            text.setText(String.valueOf(clibusinessname));
 
        return view;
    }
 
 
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder