title: Is there any way to clear displayed data on listview that receive from php under OnItemSelectedListener?
body: <p>I am doing an Android APP that display data (receive from php) according by day (I have a spinner for that).</p>
  
  <p>Now when I select second day, the data of first day will keep, is that anyway to clear that before display second day data ?</p>
  
  <p>Example:</p>
  
  <pre><code>=When I click first day=
  
  [Spinner] - day 1
  
  [listview] day 1 data
  
  
  
  =When I click second day= 
  
  [Spinner] - day 2 
  
  [listview] day 1 data  &lt;--- need to delete this
  
  [listview] day 2 data
  </code></pre>
  
  <p>activity.java</p>
  
  <pre><code>//code for spinner inside onCreate()
  Spinner spinner = (Spinner) findViewById(R.id.day_spinner);
      ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(
              this, R.array.day_spinner_items, android.R.layout.simple_spinner_item);
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spinner.setAdapter(adapter);
  
      spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
              switch (position) {
                  case 0:
                      day="1";
                      getData();
                      break;
                  case 1:
                      day="2";
                      getData();
                      break;
              }
          }
  
  
  
  //display data
  protected void showList() {
      try {
          JSONObject jsonObj = new JSONObject(myJSON);
          peoples = jsonObj.getJSONArray(TAG_RESULTS);
  
          for (int i = 0; i &lt; peoples.length(); i++) {
              JSONObject c = peoples.getJSONObject(i);
              String code = c.getString(TAG_CODE);
              String subject = c.getString(TAG_SUBJECT);
              String day = c.getString(TAG_DAY);
              String start = c.getString(TAG_START);
              String end = c.getString(TAG_END);
              String location = c.getString(TAG_LOCATION);
  
              HashMap&lt;String, String&gt; persons = new HashMap&lt;String, String&gt;();
  
              persons.put(TAG_CODE, code);
              persons.put(TAG_SUBJECT, subject);
              persons.put(TAG_DAY, day);
              persons.put(TAG_START, start);
              persons.put(TAG_END, end);
              persons.put(TAG_LOCATION, location);
  
              personList.add(persons);
          }
  
          ListAdapter adapter = new SimpleAdapter(
                  TimeActivity.this, personList, R.layout.time_listitem,
                  new String[]{TAG_CODE, TAG_SUBJECT, TAG_DAY, TAG_START, TAG_END, TAG_LOCATION},
                  new int[]{R.id.code, R.id.subject, R.id.day, R.id.start, R.id.end, R.id.location}
          );
  
          list.setAdapter(adapter);
      } catch (JSONException e) {
          e.printStackTrace();
      }
  
  }
  
  //get data from php
  public void getData() {
      class GetDataJSON extends AsyncTask&lt;String, Void, String&gt; {
  
          @Override
          protected String doInBackground(String... params) {
  
  
              // Depends on your web service
              //httppost.setHeader("Content-type", "application/json");
              List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
              nameValuePairs.add(new BasicNameValuePair("day", day));
  
              InputStream inputStream = null;
              String result = null;
              try {
                  HttpClient httpclient = new DefaultHttpClient();
                  HttpPost httppost = new HttpPost("http://192.168.1.12/android/fetchtime.php");
                  httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                  HttpResponse response = httpclient.execute(httppost);
                  HttpEntity entity = response.getEntity();
  
                  inputStream = entity.getContent();
                  // json is UTF-8 by default
                  BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
                  StringBuilder sb = new StringBuilder();
  
                  String line = null;
                  while ((line = reader.readLine()) != null) {
                      sb.append(line + "\n");
                  }
                  result = sb.toString();
              } catch (ClientProtocolException e) {
                  e.printStackTrace();
              } catch (UnsupportedEncodingException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              return result;
          }
  
          @Override
          protected void onPostExecute(String result) {
              myJSON = result;
              showList();
          }
      }
      GetDataJSON g = new GetDataJSON();
      g.execute();
  }
  </code></pre>