更新TextView-Text并用Internet数据填充它

时间:2015-12-29 16:57:44

标签: android

我有一个带有textview的Listview。单击convertview后,将调用该方法:

 private void getAmountFromItem() {
            String url = "http://192.168.192.200/getAmountFromItem.php?amount_id=" + amountIDTest;
            Log.e("URLUZ", "is " + url);
            // making fresh volley request and getting json
            JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.GET,
                    url, null, new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    VolleyLog.d(TAG, "Response: " + response.toString());
                    if (response != null) {
                        try {
                            JSONArray feedArray = response.getJSONArray("feed");

                            for (int i = 0; i < feedArray.length(); i++) {
                                feedObj = (JSONObject) feedArray.get(i);

                                Log.e("COUNTS", " " + feedObj.getString("count"));
                                textView.setText(feedObj.getString("count") + " count yeah");
                                textView.invalidate();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                }
            });

            // Adding request to volley request queue
            AppController.getInstance().addToRequestQueue(jsonReq);
        }

我尝试在“runOnUiThread”或“textView.post(new Runnable)”中设置文本...但这些不起作用..有什么建议吗?

1 个答案:

答案 0 :(得分:0)

你应该看到this&#34;解决方案&#34; (从排球中更新ui对象的最佳实践)