title: Refresh ListView using listadapter?
body: <p>I would like to refresh the ListView every time I change the base data. Please see the following
  example:</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      mListUsers = getUsers();
  lvList = (ListView) findViewById(R.id.event_list);
  lvList.setAdapter(new ListAdapter(mContext, R.id.event_list, mListUsers));
  
      btn_next=(Button)findViewById(R.id.btn_next);
  btn_next.setOnClickListener(new OnClickListener() {
  
  @Override
  public void onClick(View v) {
  // TODO Auto-generated method stub
   SimpleDateFormat postFormater = new SimpleDateFormat("dd-MMM-yyyy",Locale.ENGLISH); 
   String newDateStr = lbl_date.getText().toString();         
   Calendar c = Calendar.getInstance();
   try {
   c.setTime(postFormater.parse(newDateStr));
   } catch (ParseException e) {
  // TODO Auto-generated catch block
   e.printStackTrace();
  }
  c.add(Calendar.DATE, 1);  // number of days to add
  newDateStr = postFormater.format(c.getTime());
  lbl_date.setText(newDateStr.toString());
  
  mListUsers = getUsers();
  lvList = (ListView) findViewById(R.id.event_list);
  lvList.setAdapter(new ListAdapter(mContext, R.id.event_list, mListUsers));
  }
  });
  </code></pre>
  
  <p>}</p>
  
  <pre><code>public ArrayList&lt;main_list_item&gt; getUsers(){                
  DBAdapter dbAdapter=DBAdapter.getDBAdapterInstance(this);
  try {
              dbAdapter.createDataBase();
          } catch (IOException e) {
              Log.i("*** select ",e.getMessage());
          }
          dbAdapter.openDataBase();
  
          SimpleDateFormat curFormater1 = new SimpleDateFormat("yyyy-MM-dd");
          String dateString = curFormater1.format(new Date(lbl_date.getText().toString()));
          String query;       
          if(all==1){
              query="SELECT id,dateS, dateE, (select eventname from tbEvent_name where tbEvent_name.id=eventId)as event FROM tbTransaction";
          }
          else{
              query="SELECT id,dateS, dateE, (select eventname from tbEvent_name where tbEvent_name.id=eventId)as event FROM tbTransaction WHERE SUBSTR(sDate,1,10)='"+dateString+"'";
          }
  
          ArrayList&lt;ArrayList&lt;String&gt;&gt; stringList = dbAdapter.selectRecordsFromDBList(query, null);
          dbAdapter.close();
  
          SimpleDateFormat curFormater = new SimpleDateFormat("yyyy-MM-dd",Locale.ENGLISH);
          Date dateObj = null;
  
          ArrayList&lt;main_list_item&gt; usersList = new ArrayList&lt;main_list_item&gt;();
          for (int i = 0; i &lt; stringList.size(); i++) {
              ArrayList&lt;String&gt; list = stringList.get(i);
              main_list_item user = new main_list_item();
              try {
                  user.id=Integer.parseInt(list.get(0));
                  user.event= list.get(3);
  
          String newDateStr1 = postFormater1.format(dateObj);
  
                  user.dateS=list.get(1);
                  user.dateE=list.get(2);
  
              } catch (Exception e) {
                  e.printStackTrace();
              }
              usersList.add(user);
          }
          return usersList;
      }
  
   // ***ListAdapter***
      private class ListAdapter extends ArrayAdapter&lt;main_list_item&gt; {  // --CloneChangeRequired
          private ArrayList&lt;main_list_item&gt; mList;  // --CloneChangeRequired
          private Context mContext;
  
          public ListAdapter(Context context, int textViewResourceId,ArrayList&lt;main_list_item&gt; list) { // --CloneChangeRequired
              super(context, textViewResourceId, list);
              this.mList = list;
              this.mContext = context;
          }
  
          public View getView(int position, View convertView, ViewGroup parent){
              View view = convertView;
              try{
              if (view == null) {
                  LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                  view = vi.inflate(R.layout.main_list_item, null);   // --CloneChangeRequired(list_item)
              }
              final main_list_item listItem = mList.get(position);    // --CloneChangeRequired                
              if (listItem != null) {
                  // setting list_item views                      
                  ((TextView) view.findViewById(R.id.lbl_id) ).setText( listItem.getId()+"");
  
                  ((TextView) view.findViewById(R.id.lbl_event) ).setText( listItem.getEvent()+"");
                  ((TextView) view.findViewById(R.id.lbl_sdate) ).setText( listItem.getsDate()+"");
                  ((TextView) view.findViewById(R.id.lbl_edate) ).setText( listItem.geteDate()+"");
  
              }}catch(Exception e){
                  e.printStackTrace();
              }
  
              return view;
          }       
      }
  </code></pre>
  
  <p>Its is correct way?</p>
  
  <p>In this code I want to refresh listview when 'btn_next' click.</p>
  
  <p>And also I  want to separate two parts,put heading. </p>
  
  <p>please give me guide..</p>
  
  <p>thanks in advance</p>
  
  <pre><code>Uncaught handler: thread main exiting due to uncaught exception
  java.lang.NullPointerException
  at com.apt.eTrack.ETrackActivity$4.onClick(ETrackActivity.java:153)
  at android.view.View.performClick(View.java:2344)
  at android.view.View.onTouchEvent(View.java:4133)
  at android.widget.TextView.onTouchEvent(TextView.java:6510)
  at android.view.View.dispatchTouchEvent(View.java:3672)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
  at    com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1712)
  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1202)
  at android.app.Activity.dispatchTouchEvent(Activity.java:1987)
  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1696)
  at android.view.ViewRoot.handleMessage(ViewRoot.java:1658)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:123)
  at android.app.ActivityThread.main(ActivityThread.java:4203)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:521)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
  at dalvik.system.NativeStart.main(Native Method)
  Unable to open stack trace file '/data/anr/traces.txt': Permission denied
  </code></pre>