I send POST request and get JSON object. I have parsed it, but when I'm trying to add it to the ArrayList for RecyclerView, I get 0 size of ArrayList. My AsyncTask:
new AsyncTask<Void, Void, Void>() {
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(LectorsListActivity.this, null, "Please Wait", true, false);
}
@Override
protected Void doInBackground(Void... params) {
try {
LoginLectorUtils httpUtils = new LoginLectorUtils();
String name, uniqueId, photoUrl;
JSONArray array = new JSONArray(httpUtils.sendPostRequest(REQUEST_URL));
for (int i = 0; i < array.length(); i++) {
JSONObject jsonObject = array.getJSONObject(i);
name = jsonObject.getString("name");
uniqueId = jsonObject.getString("unique_id");
photoUrl = jsonObject.getString("photo_url");
//if (!name.equals("") && !uniqueId.equals("") && !photoUrl.equals("")) {
data.add(new LectorsDataModel(name, uniqueId, photoUrl)); // Here i'm adding new items
//}
}
} catch (Exception e) {
Log.e("LectorsListActivity", "Can't create JSONArray");
}
return null;
}
@Override
protected void onPostExecute(final Void str) {
super.onPostExecute(str);
loading.dismiss();
}
}.execute();
//data = new ArrayList<LectorsDataModel>();
//data.add(new LectorsDataModel("", "", ""));
Toast.makeText(LectorsListActivity.this, Integer.toString(data.size()), Toast.LENGTH_SHORT).show(); // Shows 0
adapter = new LectorsAdapter(data, this);
recyclerView.setAdapter(adapter);
asyncmeans inasynctask.