how to add swipe to refresh to my code,After adding data when i go back to the activity where the list view is present the list remains the same.how to refresh it.
please help..
thanks in advance
What I have tried:
public class TrainingActivity extends ActionBarActivity {
private String jsonResult;
public String url ="";
ListView listView;
List<Map<string,string>> activity = new ArrayList<Map<string,string>>();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_training);
listView = (ListView) findViewById(R.id.listView);
accessWebService();
}
private class JsonReadTask extends AsyncTask<string,>
{
@Override
protected String doInBackground(String... params)
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(params[0]);
try{
HttpResponse response = httpclient.execute(httppost);
jsonResult = inputStreamToString(
response.getEntity().getContent()).toString();
}catch(ClientProtocolException e){
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
return null;
}
private StringBuilder inputStreamToString(InputStream is){
String rLine ="";
StringBuilder answer = new StringBuilder();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
try{
while((rLine = rd.readLine()) != null){
answer.append(rLine);
}
}catch(IOException e){
Toast.makeText(getApplicationContext(),"error ..." + e.toString(), Toast.LENGTH_LONG).show();
}
return answer;
}
@Override
protected void onPostExecute(String result){
ListDrwaer(); // we will create it later
}
}
public void accessWebService(){
JsonReadTask task = new JsonReadTask();
task.execute(new String[] {url});
}
public void ListDrwaer (){
try{
JSONObject jsonResonse = new JSONObject(jsonResult.substring(jsonResult.indexOf("{"), jsonResult.lastIndexOf("}")+1));
JSONArray jsonMainNode = jsonResonse.optJSONArray("activity");
final ArrayList<hashmap><string,string>> MyArrList = new ArrayList<hashmap><string,>>();
HashMap<string,string> map;
for(int i=0; i<jsonmainnode.length();> JSONObject c = jsonMainNode.getJSONObject(i);
map = new HashMap<string,string>();
map.put("activity", c.getString("activity"));
map.put("time", c.getString("time"));
map.put("date", c.getString("date"));
MyArrList.add(map);
SimpleAdapter sAdap;
sAdap = new SimpleAdapter(TrainingActivity.this, MyArrList, R.layout.activity_column, new String[]{"activity","time","date"}, new int[]{R.id.ColMemberID, R.id.ColName, R.id.Colcity});
listView.setAdapter(sAdap);
}
}catch (JSONException e){
Toast.makeText(getApplicationContext(),"error ..." + e.toString(), Toast.LENGTH_LONG).show();
}
}
}