I have a module in my application which uses json.
The json gets updated always.
Here i want to refresh the screen as new data arrives.
Is there any method for this ?
I want to refresh the screen as new data arrives or once in every 5 seconds or something(a fixed amount of time).How to do this ?
I simply used a local json file to test this.
I just need the code for refreshing.
This is my code for json parsing :
public class MainActivity extends Activity { String myjsonstring; ArrayList<Data> web = new ArrayList<Data>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); JsonParser(); // Try to parse JSON try { JSONObject jsonObjMain = new JSONObject(myjsonstring); JSONArray jsonArray = jsonObjMain.getJSONArray("pgm"); for (int i = 0; i < jsonArray.length(); i++) { // Creating JSONObject from JSONArray JSONObject jsonObj = jsonArray.getJSONObject(i); // Getting data from individual JSONObject Data data = new Data(jsonObj.getString("name") , jsonObj.getString("viewers")); web.add(data); } final customtest1 adapter = new customtest1(MainActivity.this,R.layout.list_single,web); ListView list = (ListView)findViewById(R.id.list); list.setAdapter(adapter); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(MainActivity.this, "Test.........", Toast.LENGTH_SHORT).show(); adapter.notifyDataSetChanged(); } }); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private void JsonParser() { // Reading text file from assets folder StringBuffer sb = new StringBuffer(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getAssets().open( "main.json"))); String temp; while ((temp = br.readLine()) != null) sb.append(temp); } catch (IOException e) { e.printStackTrace(); } finally { try { br.close(); // stop reading } catch (IOException e) { e.printStackTrace(); } } myjsonstring = sb.toString(); } }