title: Refreshing screen which uses json in android
body: <p>I have a  module in my application which uses json.</p>
  
  <p>The json gets updated always.</p>
  
  <p>Here i want to refresh the screen as new data arrives.</p>
  
  <p>Is there any method for this ?</p>
  
  <p>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 ?</p>
  
  <p>I simply used a local json file to test this.</p>
  
  <p><strong>I just need the code for refreshing.</strong></p>
  
  <p>This is my code for json parsing :</p>
  
  <pre><code>public class MainActivity extends Activity 
  {
      String myjsonstring;
  
       ArrayList&lt;Data&gt; web = new ArrayList&lt;Data&gt;();
  
       @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 &lt; 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&lt;?&gt; 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();
  
      }
      }
  </code></pre>