title: ListView not updating after inserting data through an Android DialogBox?
body: <p>hi all Am having listview which displays list of items from sqlite db. Using DialogBox am inserting data in DB. Insertion done successfully. But if i entered data on DialogBox and click ok button, the data inserted in db but the inserted data is not displaying in ListView.</p>
  
  <p>ListView is not refreshing.... I hv used <code>adapter.setNotifyOnChange(true);</code>. But this wont take any effect on listview. </p>
  
  <p>And I have got warning on logcat as</p>
  
  <pre><code>`09-16 15:01:10.215: INFO/dalvikvm(2066): Uncaught exception thrown by finalizer (will be discarded):
  09-16 15:01:10.215: INFO/dalvikvm(2066): Ljava/lang/IllegalStateException;: Finalizing cursor android.database.sqlite.SQLiteCursor@44c4be28 on PAYMENT_TABLE that has not been deactivated or closed
  09-16 15:01:10.215: INFO/dalvikvm(2066):     at android.database.sqlite.SQLiteCursor.finalize(SQLiteCursor.java:596)
  09-16 15:01:10.215: INFO/dalvikvm(2066):     at dalvik.system.NativeStart.run(Native Method)`
  </code></pre>
  
  <p>But i hv closed the cursor in OnDestory()</p>
  
  <p>Here is my code.</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
  
      mySQLiteAdapter = new SQLiteAdapter(this);         
      mySQLiteAdapter.openToWrite();
      cursor = mySQLiteAdapter.queueAll();
  
      cursor.moveToFirst();
      while(!cursor.isAfterLast()) {          
          String mTitleRaw = cursor.getString(cursor.getColumnIndex(SQLiteAdapter.KEY_PAYMENT_TYPE));
          al.add(mTitleRaw);
          cursor.moveToNext();
          }    
  
      adapterChanged();
  }
  
  @SuppressWarnings("unchecked")
  private void adapterChanged() {
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
              android.R.layout.simple_list_item_multiple_choice, al);
  
      adapter.setNotifyOnChange(true);
      setListAdapter(adapter);
  
      listContent = getListView();
      listContent.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
  }
  
  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
      // TODO Auto-generated method stub
      super.onListItemClick(l, v, position, id);
      //Object o = this.getListAdapter().getItem(position);
  }
  
  @Override
  protected void onDestroy() {
      // TODO Auto-generated method stub
      super.onDestroy();
      if (mySQLiteAdapter != null) {
          mySQLiteAdapter.close();
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // TODO Auto-generated method stub
      menu.add(0, MENU_ADD, 0, "Add New");                
      return super.onCreateOptionsMenu(menu);
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // TODO Auto-generated method stub
      switch(item.getItemId()) {      
      case MENU_ADD:
          AlertMsg();         
          return true;        
      }
      return super.onOptionsItemSelected(item);
  }
  
  private void updateList(){
      cursor.requery();
      }   
  
  public void AlertMsg() {
      AlertDialog.Builder alert = new AlertDialog.Builder(this);
      alert.setTitle("Payment Type");
      alert.setMessage("Add field");
      final EditText mTxt = new EditText(this);
      alert.setView(mTxt);
      alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
  
          public void onClick(DialogInterface dialog, int which) {
              // TODO Auto-generated method stub              
              String mNewField = mTxt.getText().toString();
              //Toast.makeText(getApplicationContext(), "Item " + mNewField + " Added", Toast.LENGTH_LONG).show();
              mySQLiteAdapter.insert(mNewField);
              updateList();
  
              adapterChanged();
          }
      });
      alert.show();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Are this efficient way....</p>
  
  <p>Can anyone pls give some suggestions.....</p>
  
  <p>Thanks......</p>