title: How to refresh or update listview using BaseAdapter?
body: <p>I have been trying to refresh the <code>listview</code> whenever I delete the row in it. I have used <code>BaseAdapter</code> for <code>listview</code>. I am not getting how to refresh it. I used SQLite and while refreshing I am deleting the row in Database as well.</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      DataBase md ;
      ImageButton ib;
      ListView notelist;
      int i;
      ArrayList&lt;String&gt; titles = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; not = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; date = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; time = new ArrayList&lt;String&gt;();
  
      ArrayList&lt;String&gt; Revtitles = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; Revnot = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; Revdate = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; Revtime = new ArrayList&lt;String&gt;();
  
  
      DataAdapter adapter;
  
      View view;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          md = new DataBase(this);
  
          SQLiteDatabase sd = md.getReadableDatabase();
  
          Cursor c = sd.query(md.TABLE_NAME, null, null, null, null, null, null);
  
          while (c.moveToNext()) {
  
              titles.add(c.getString(0));
              not.add(c.getString(1));
              date.add(c.getString(2));
              time.add(c.getString(3));
  
          }
  
          for (int i = titles.size() - 1; i &gt;= 0; i--) {
  
              Revtitles.add(titles.get(i));
              Revnot.add(not.get(i));
              Revdate.add(date.get(i));
              Revtime.add(time.get(i));
  
          }
  
          notelist = (ListView) findViewById(R.id.listView1);
          ib = (ImageButton) findViewById(R.id.imageButton1);
  
          adapter = new DataAdapter(this);
          notelist.setAdapter(adapter);
          // notelist.setStackFromBottom(true);
          notelist.setOnItemClickListener(new OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2,
                      long arg3) {
                  // TODO Auto-generated method stub
                  Intent i = new Intent(MainActivity.this,Show.class);
  
                  i.putExtra("TITLE", Revtitles.get(arg2));
                  i.putExtra("NOTE", Revnot.get(arg2));
  
                  startActivity(i);
                  finish();
  
              }
          });
  
          notelist.setOnItemLongClickListener(new OnItemLongClickListener() {
  
              @Override
              public boolean onItemLongClick(AdapterView&lt;?&gt; parent, View v,
                      final int pos, long arg3) {
                  // TODO Auto-generated method stub
                  final String st = Revtitles.get(pos);
                  String st1 = Revnot.get(pos);
  
                  AlertDialog.Builder ad = new AlertDialog.Builder(MainActivity.this);
                  ad.setMessage("Are sure you want to delete?");
                  ad.setCancelable(false);
                  ad.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
  
                      @Override
                      public void onClick(DialogInterface arg0, int arg1) {
                          // TODO Auto-generated method stub
  
                      //sd.delete(md.TABLE_NAME, md.COL_ROLLNO+"=?", new String[]{st});
  
                      //Intent i = new Intent(MainActivity.this,MainActivity.class);
                      //startActivity(i);
  
                  ///////PROBLEM LINES///////
  
  
  
                          SQLiteDatabase sd = md.getWritableDatabase();
  
                          sd.delete(md.TABLE_NAME,md.COL_TITLE+"=?", new String[]{st});
  
                          Revtitles.remove(pos);
                          Revnot.remove(pos);
                          Revdate.remove(pos);
                          Revtime.remove(pos);
  
                          adapter.notifyDataSetChanged();
                          adapter.notifyDataSetInvalidated();
  
                          notelist.setAdapter(adapter);
  
                      }
  
  
  
                  });
                  ad.setNegativeButton("No", new DialogInterface.OnClickListener() {
  
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          // TODO Auto-generated method stub
                          dialog.dismiss();
                      }
                  });
  
                  AlertDialog adl = ad.create();
                  adl.show();
                  return true;
              }
  
          });
  
          ib.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  Intent i = new Intent(MainActivity.this, Add.class);
                  startActivity(i);
                  finish();
              }
          });
  
      }
  
      class DataAdapter extends BaseAdapter{
  
          private Context con;
          LayoutInflater lat = getLayoutInflater();
  
          public DataAdapter(MainActivity mainActivity) {
              // TODO Auto-generated constructor stub
              this.con = mainActivity;
          }
  
          @Override
          public int getCount() {
              // TODO Auto-generated method stub
              return titles.size();
          }
  
          @Override
          public Object getItem(int arg0) {
              // TODO Auto-generated method stub
              return null;
          }
  
          @Override
          public long getItemId(int arg0) {
              // TODO Auto-generated method stub
              return 0;
          }
  
          @Override
          public View getView(int position, View convo, ViewGroup arg2) {
              // TODO Auto-generated method stub
              convo = lat.inflate(R.layout.mainlist, null);
  
              TextView tit = (TextView)convo.findViewById(R.id.inflatetitle);
              TextView datea = (TextView)convo.findViewById(R.id.inflatedate);
              String rtitle;
  
              int len = Revtitles.get(position).length();
              if (len &lt;= 20){
               rtitle = Revtitles.get(position);
              }
              else {
                  rtitle = Revtitles.get(position).substring(0, 20) + "...";
              }
              tit.setText(rtitle);
              datea.setText(Revdate.get(position) + "\n" + Revtime.get(position));
  
              view = convo;
              return convo;
          }
  
      }
      @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
          // TODO Auto-generated method stub
          if (keyCode == KeyEvent.KEYCODE_BACK) {
              finish();
          }
          return super.onKeyDown(keyCode, event);
      }
  
  }
  </code></pre>