Skip to content Skip to sidebar Skip to footer

Populating Listview From Json

I know that this question is asked 100 times, but for some reason i cannot find what is wrong in my code. I am very new to android and java. Basically i have a wordpress website f

Solution 1:

After updating the data, try something like refreshing the list view like lstTest.invalidateViews(); - so your queryImp() code will change into:

privatevoidqueryImp() {
// Create a client to perform networkingAsyncHttpClient client = newAsyncHttpClient();
   client.get("http://example.com/wp-json/wp/v2/posts",
       newJsonHttpResponseHandler() {
                    @OverridepublicvoidonSuccess(JSONArray jsonArray) {
                        Toast.makeText(getApplicationContext(), "Success!", Toast.LENGTH_LONG).show();

                        mJSONAdapter.updateData(jsonArray);
                        mJSONAdapter.notifyDataSetChanged();
                        //try refreshing the list-view like this:
                        lstTest.invalidateViews()
                    }

                    @OverridepublicvoidonFailure(int statusCode, Throwable throwable, JSONObject error) {
                        // Display a "Toast" message// to announce the failureToast.makeText(getApplicationContext(), "Error: " + statusCode + " " + throwable.getMessage(), Toast.LENGTH_LONG).show();

                        // Log error message// to help solve any problemsLog.e("Imp android", statusCode + " " + throwable.getMessage());
                    }
                });

    }

Let me know if the changes help.

Post a Comment for "Populating Listview From Json"