Issue
My question is how can i add a message "Loading please wait " . Until the request is made and response is parsed to table.
Is there approach to that using this method ?
Like this when i run this i don't know if there is no data on response or response is not yet received.
StringRequest postRequest = new StringRequest(Request.Method.POST, apiURL,
new Response.Listener<String>()
{
@Override
public void onResponse(String response) {
try {
JSONObject jsonObj = new JSONObject(response);
JSONArray jsonArray = jsonObj.getJSONArray("sales");
for (int i=0;i<jsonArray.length();i++){
JSONObject employee = jsonArray.getJSONObject(i);
TableRow tbrow = new TableRow( MainActivity.this );
TextView t1v = new TextView(MainActivity.this);
t1v.setText(employee.getString("saletype"));
t1v.setTextColor(Color.BLACK);
stk.addView(tbrow);
// .......
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
}
}
) {
@Override
protected Map<String, String> getParams()
{
Map<String, String> params = new HashMap<String, String>();
Spinner spinner = (Spinner) findViewById(R.id.spinner);
params.put("store", spinner.getSelectedItem().toString());
return params;
}
};
mQueue.add(postRequest);
Solution
Show Progress bar on adding request object in queue.
mQueue.add(postrequest);
progressDialog = new ProgressDialog(getActivity());
progressDialog.setMessage("Loading ...Please Wait");
progressDialog.show();
Then Dismiss it on receiving response.
try {
JSONObject jsonObj = new JSONObject(response);
JSONArray jsonArray = jsonObj.getJSONArray("sales");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject employee = jsonArray.getJSONObject(i);
TableRow tbrow = new TableRow(MainActivity.this);
TextView t1v = new TextView(MainActivity.this);
t1v.setText(employee.getString("saletype"));
t1v.setTextColor(Color.BLACK);
stk.addView(tbrow);
// .......
}
progressDialog.dismiss();
} catch (Exception e) {
progressDialog.dismiss();
}
Also,
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.dismiss();
}
Answered By - Prince Sharzeel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.