title: How to refresh ListView dynamically?
body: <p>I am making a ListView with TextView and 1 delete button for each row.  </p>
  
  <p>To populate the list I am using my custom adaptor (extends base adapter) and sqlite db to map into list.</p>
  
  <p>My requirement is onclick of delete button in a row that record should be deleted and list should refresh.</p>
  
  <p>I am able to delete record from db but my list is not refreshing until I rotate the device or assign a new instance of my adapter from activity.</p>
  
  <p>I have tried following <a href="https://stackoverflow.com/questions/7831395/android-how-to-delete-a-row-from-a-listview-with-a-delete-button-in-the-row">answer</a>
     but didn't work in my case. the difference between this answer and my case is I am using baseAdapter and he is using cursorAdapter.</p>
  
  <pre><code> public class BookmarksPDFAdapter extends BaseAdapter { 
  
              public View getView(int position, View convertView, ViewGroup parent) {
              openDatabase();
  
  
  
  
              btnDelete.setOnClickListener(new OnClickListener() {
  
                  @Override
                  public void onClick(View v) {
  
                      deleteBookmark(getLocation(v));//getlocation(View) method returns which delete button clicked
                      notifyDataSetChanged();
  
                  }
              });
          }
          closeDatabase();
          return convertView;
      }
  </code></pre>
  
  <p>my activity looks like</p>
  
  <pre><code>public class BookmarkActivity extends Activity {
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.bookmarks);
      btnEdit = (Button) findViewById(R.id.edit_bookmarks);
      btnAdd = (Button) findViewById(R.id.add_bookmarks);
  
      list = (ListView) findViewById(android.R.id.list);
  
      adapter = new BookmarksPDFAdapter(this);
  
      list.setAdapter(adapter);
  }
  </code></pre>
  
  <p>bookmark.xml</p>
  
  <pre><code>&lt;LinearLayout 
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
  android:weightSum="10.0" 
  android:paddingTop="5dp"&gt;
  
  &lt;LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
  
      android:padding="3dip"
      android:layout_alignParentLeft="true"
      android:weightSum="1.0" 
      android:layout_marginRight="5dip"&gt;
  
      &lt;ImageView
          android:id="@+id/iconShow"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/delete_icon"
          android:visibility="invisible" 
          android:layout_weight="1.0"/&gt;
  &lt;/LinearLayout&gt;
  
  &lt;TextView
      android:id="@+id/bookmark_text"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginTop="6dp"
      android:layout_weight="7.0"
      android:gravity="center_horizontal|center_horizontal"
      android:lines="1"
      android:text="@+id/TextView01"
      android:textSize="24dp" /&gt;
  
  &lt;Button
      android:id="@+id/btnDelete"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="right"
      android:layout_weight="2.0"
      android:text="@string/btn_txt_delete"
      android:visibility="invisible" &gt;
  &lt;/Button&gt;
  </code></pre>
  
  <p></p>
  
  <p>listitem.xml</p>
  
  <pre><code>&lt;LinearLayout 
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
  android:weightSum="10.0" 
  android:paddingTop="5dp"&gt;
  
  &lt;LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
  
      android:padding="3dip"
      android:layout_alignParentLeft="true"
      android:weightSum="1.0" 
      android:layout_marginRight="5dip"&gt;
  
      &lt;ImageView
          android:id="@+id/iconShow"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/delete_icon"
          android:visibility="invisible" 
          android:layout_weight="1.0"/&gt;
  &lt;/LinearLayout&gt;
  
  &lt;TextView
      android:id="@+id/bookmark_text"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginTop="6dp"
      android:layout_weight="7.0"
      android:gravity="center_horizontal|center_horizontal"
      android:lines="1"
      android:text="@+id/TextView01"
      android:textSize="24dp" /&gt;
  
  &lt;Button
      android:id="@+id/btnDelete"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="right"
      android:layout_weight="2.0"
      android:text="@string/btn_txt_delete"
      android:visibility="invisible" &gt;
  &lt;/Button&gt;
  </code></pre>
  
  <p></p>
  
  <p>deleteBookmark method</p>
  
  <pre><code>void deleteBookmark(int wantedChild) {
  
      String bookmarkItem = getBookmarkItemText(wantedChild, true);
      datasource.open();
      int check = datasource.deleteBookmark(bookmarkItem);
      if (check == 1) {
  
          btnDelete = (Button) (viewList.get(wantedChild)
                  .findViewById(R.id.btnDelete));
  
          btnDelete.setText(R.string.btn_txt_deleted);
          btnDelete.setEnabled(false);
      }
  
      datasource.close();
  }
  </code></pre>
  
  <p>Here I am deleting record from my database and changing text of delete button from <strong>delete</strong> to <strong>deleted</strong></p>