private class MyTask extends AsyncTask<String, Void, String> {
ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(ActivityNewsListByCategory.this);
progressDialog.setMessage("Yükleniyor...");
progressDialog.setCancelable(false);
progressDialog.show();
}
@Override
protected String doInBackground(String... params) {
return JsonUtils.getJSONString(params[0]);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (null != progressDialog && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (null == result || result.length() == 0) {
Toast.makeText(getApplicationContext(), "İnternet Bağlantınızı Kontrol Edin !!", Toast.LENGTH_SHORT).show();
} else {
try {
JSONObject mainJson = new JSONObject(result);
JSONArray jsonArray = mainJson.getJSONArray(JsonConfig.CATEGORY_ARRAY_NAME);
JSONObject objJson = null;
for (int i = 0; i < jsonArray.length(); i++) {
objJson = jsonArray.getJSONObject(i);
ItemNewsList objItem = new ItemNewsList();
objItem.setCId(objJson.getString(JsonConfig.CATEGORY_ITEM_CID));
objItem.setCategoryName(objJson.getString(JsonConfig.CATEGORY_ITEM_NAME));
objItem.setCategoryImage(objJson.getString(JsonConfig.CATEGORY_ITEM_IMAGE));
objItem.setCatId(objJson.getString(JsonConfig.CATEGORY_ITEM_CAT_ID));
objItem.setNewsImage(objJson.getString(JsonConfig.CATEGORY_ITEM_NEWSIMAGE));
objItem.setNewsHeading(objJson.getString(JsonConfig.CATEGORY_ITEM_NEWSHEADING));
objItem.setNewsDescription(objJson.getString(JsonConfig.CATEGORY_ITEM_NEWSDESCRI));
objItem.setNewsDate(objJson.getString(JsonConfig.CATEGORY_ITEM_NEWSDATE));
list.add(objItem);
}
} catch (JSONException e) {
e.printStackTrace();
}
for (int j = 0; j < list.size(); j++) {
object = list.get(j);
array_cat_id.add(object.getCatId());
str_cat_id = array_cat_id.toArray(str_cat_id);
array_cat_name.add(object.getCategoryName());
str_cat_name = array_cat_name.toArray(str_cat_name);
array_cid.add(String.valueOf(object.getCId()));
str_cid = array_cid.toArray(str_cid);
array_image.add(String.valueOf(object.getNewsImage()));
str_image = array_image.toArray(str_image);
array_title.add(String.valueOf(object.getNewsHeading()));
str_title = array_title.toArray(str_title);
array_desc.add(String.valueOf(object.getNewsDescription()));
str_desc = array_desc.toArray(str_desc);
array_date.add(String.valueOf(object.getNewsDate()));
str_date = array_date.toArray(str_date);
}
setAdapterToListview();
}
}
}
Yukardaki Gibi Kullanmaktayım Program Herhangi bir hata vermemekte ancak konuların çok olduğu bir kategoride herhangi bir başlığı açtığımda program önce anasayfaya gönmekte bir süre sonrada kendini kapatmaktadır