I have been using loopj library to interact with my server. I have created a view pager inside a fragment and thus created child fragments In these child fragment when I send a request to the server I get correct response. The problem arises when I send the refresh request to the server ,the response is still correct but the UI becomes black tinted and I cannot interact with UI anymore.
Screen looks like this after first request:
And after second request the screen becomes
My Code for connecting with server is :
private void setWatchlistData() {
String url = "";
switch (watchlist_type) {
case 1:
url = "/getWatchList";
break;
case 2:
url = "/getTrendingWatchList";
break;
case 3:
url = "/getRecommendedWatchList";
break;
}
responseHandler = new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, cz.msebera.android.httpclient.Header[] headers, JSONObject response) {
if (progressDialog.isShowing()) {
progressDialog.dismissWithAnimation();
if (swipeRefresh.isRefreshing())
swipeRefresh.setRefreshing(false);
try {
Log.d(TAG, response.toString());
if (!response.isNull("status")) {
if (response.getBoolean("status")) {
assets = new ArrayList<Asset>();
JSONArray arr = response.getJSONArray("watchlist");
for (int i = 0; i < arr.length(); i++) {
JSONObject obj = arr.getJSONObject(i);
Asset a = new Asset();
a.setType(new AssetType(obj.getJSONObject("type")));
a.setName(obj.getString("name"));
a.setId(obj.getInt("id"));
switch (a.getType().getType()) {
case AssetType.ASSET_TYPE_STOCK:
a.setSymbol(obj.getString("symbol"));
assets.add(a);
break;
}
}
setData();
} else {
new SweetAlertDialog(getActivity(), SweetAlertDialog.ERROR_TYPE).setTitleText("Error").setContentText(response.getString("message")).setConfirmText("Ok").setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sweetAlertDialog) {
sweetAlertDialog.dismiss();
}
}).show();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, String responseString, Throwable throwable) {
Log.d(TAG, responseString + "");
progressDialog.dismissWithAnimation();
new SweetAlertDialog(getActivity(), SweetAlertDialog.ERROR_TYPE).setTitleText("Error Occured").setContentText(responseString + "").show();
}
};
RequestParams params = new RequestParams();
params.add("user_id", String.valueOf(new UserDetailsHandler(getActivity()).getUser().getId()));
client.setTimeout(99999);
client.cancelAllRequests(true);
client.get(CommonUtils.BASE_URL + url, params, responseHandler);
progressDialog.show();
}
Swipe Refresh function:
swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
setWatchlistData();
}
});
After first call the watchlist gets updated, but on swipe refresh it shows the isssue.