title: ListView updates the entry only when the application is restarted again
body: <p>In this application, I have a <code>listview</code> and a <code>sqlitedatabase</code>. There is a <code>floating action button</code> which on clicking displays a <code>dialog box</code> containing two <code>edittext</code> one for name and another for number. The problem is that the after clicking on the <code>add</code> option of the <code>dialog box</code> the entry is not shown on the <code>listview</code>. But when the <code>activity</code> is destroyed and <code>onCreate</code> is called again on the <code>activity</code> , the entry is shown. </p>
  
  <p>I tried using <code>adapter.notifyDataSetChanged()</code> but it doesn't work. The code is shown below :</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>public class DetailsActivity extends AppCompatActivity {
  
  private DatabaseManager manager;
  private ListView listView;
  private SimpleCursorAdapter adapter;
  
  final String[] from=new String[] {UserDatabase.NAME,UserDatabase.NUMBER};
  
  final int[] to=new int[] {R.id.nameDisplay,R.id.phoneDisplay};
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_details);
  
      manager = new DatabaseManager(getApplicationContext());
      manager.open();
      Cursor cursor=manager.fetch();
  
      listView = (ListView) findViewById(R.id.listViewId);
      listView.setEmptyView(findViewById(R.id.empty));
  
      adapter = new SimpleCursorAdapter(getApplicationContext(),
              R.layout.row_item, cursor, from, to, 0);
      adapter.notifyDataSetChanged();
  
      listView.setAdapter(adapter);
  
      FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
      fab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(DetailsActivity.this);
              LayoutInflater inflater = DetailsActivity.this.getLayoutInflater();
              final View dialogView = inflater.inflate(R.layout.custom_dialog, null);
              dialogBuilder.setView(dialogView);
              final EditText name = (EditText) dialogView.findViewById(R.id.dialogEditNmID);
              final EditText phone = (EditText) dialogView.findViewById(R.id.dialogEditPhID);
  
              dialogBuilder.setTitle("Add Details");
              dialogBuilder.setPositiveButton("Add", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      if (!TextUtils.isEmpty(name.getText().toString()) &amp;&amp;
                              !TextUtils.isEmpty(phone.getText().toString())) {
                          /*adapter.notifyDataSetChanged();
                          manager.insert(name.getText().toString(), phone.getText().toString());
                          Toast.makeText(getApplicationContext(),
                                  "Added " + name.getText().toString(), Toast.LENGTH_SHORT).show();*/
                          insertData(name.getText().toString(),phone.getText().toString());
                      } else {
                          Toast.makeText(getApplicationContext(),
                                  "Empty field(s)", Toast.LENGTH_SHORT).show();
                      }
  
                  }
              });
  
              dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      dialog.dismiss();
                  }
              });
  
              AlertDialog b = dialogBuilder.create();
              b.show();
              //  listView.setAdapter(adapter);
              //adapter.notifyDataSetChanged();
          }
      });
  }
  
  public void insertData(String fname,String phnumber){
      manager.insert(fname,phnumber);
      listView.setAdapter(adapter);
      adapter.notifyDataSetChanged();
  }
  }
  </code></pre>
  
  <p>Some of the statements are commented because I tried to get the desired result but couldn't get it.</p>