In my Application I want to retrieve a data from the database. But the problem I am facing is that, the data is fetched from database but it is not displaying at a time when I reopen the page at that time the data is displaying. I want to reload a page when I click on Button.
Here the code is as follow :-
Btngetdata.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new InTimeInsert().execute();
}
});
private class InTimeInsert extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... args) {
try {
arraylist = new ArrayList<HashMap<String, String>>();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("at_username", uid));
JSONObject json = jParser.makeHttpRequest(url_intime,"GET", params);
//ownerObj = json.getJSONArray("visit");
for (int i = 0; i < ownerObj.length(); i++) {
jsonobject = ownerObj.getJSONObject(i);
time_fetch.add(jsonobject.getString("at_itime"));
}
} catch (Exception e) {
}
return null;
}
@Override
protected void onPostExecute(Void args) {
ina.setText(""+delivery_fetch);
}
}
private class AllAtendence extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... args) {
try {
arraylist = new ArrayList<HashMap<String, String>>();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("at_username", uid));
JSONObject json = jParser.makeHttpRequest(url_allatendence,"GET", params);
ownerObj = json.getJSONArray("visit");
for (int i = 0; i < ownerObj.length(); i++) {
jsonobject = ownerObj.getJSONObject(i);
delivery_fetch =jsonobject.getString("at_date");
lunch=jsonobject.getString("at_litime");
rejoin=jsonobject.getString("at_lotime");
out=jsonobject.getString("at_otime");
Log.d("at_line",json.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void args) {
ina.setText(""+delivery_fetch);
rejoina.setText(""+lunch);
luncha.setText(""+rejoin);
outa.setText(""+out);
if(ina.getText().toString().equals(""))
{
Btngetdata.setVisibility(View.VISIBLE);
inti.setVisibility(View.GONE);
}
else
{
Btngetdata.setVisibility(View.GONE);
}
if(luncha.getText().toString().equals(""))
{
ltime.setVisibility(View.VISIBLE);
luncht.setVisibility(View.GONE);
}
else
{
ltime.setVisibility(View.GONE);
}
if(rejoina.getText().toString().equals(""))
{
rtime.setVisibility(View.VISIBLE);
rejoint.setVisibility(View.GONE);
}
else
{
rtime.setVisibility(View.GONE);
}
if(outa.getText().toString().equals(""))
{
otime.setVisibility(View.VISIBLE);
outt.setVisibility(View.GONE);
}
else
{
otime.setVisibility(View.GONE);
}
}
}
If you fetch only one data than you can use this to solve your problem.. And use log to see if there is any err on fetching data... on catch block..Good luck.