How to refresh listView to after closing the dialog ?
android, android-listview
Solution
To refresh a `listView` you should call the method `notifyDataSetChanged()` on your list's adapter. When calling that method is up to you... maybe inside your `onClickListener`.
Problem
I have created a layout that opens the dialog, and after entering the dialog, the user selects ok/cancel. I want to refresh the listView to requery the data Here's my layout that would open the dialog: ``` button.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { Intent myIntent = new Intent(SchoolActivity.this, InsertSchool.class); update(); startActivity(myIntent); updateList(); } }); update(); cursor.requery(); String[] from = new String[]{Database.KEY_ID2, Database.KSCHOOL, Database.KSCHOOLCODE}; int[] to = new int[]{R.id.rid, R.id.rt1, R.id.rt2}; cursorAdapter = new SimpleCursorAdapter(this, R.layout.row_school, cursor, from, to); listContent.setAdapter(cursorAdapter); ``` After clicking that button, I want to refresh the listView. Here's the dialog (I think refreshing is going to be done here on the ok & cancel buttons). ``` ib.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Intent intent=new Intent(InsertSchool.this, SchoolActivity.class); startActivity(intent); } }); update(); mySQLiteAdapter = new Database(this); mySQLiteAdapter.openToWrite(); cursor = mySQLiteAdapter.queueSchoolAll(); ib1.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub String data1 = ie1.getText().toString(); String data2 = ie2.getText().toString(); mySQLiteAdapter.insertSchool(data1, data2); updateList(); Toast.makeText(getApplicationContext(), "Saved", Toast.LENGTH_SHORT).show(); Intent myIntent = new Intent(InsertSchool.this, SchoolActivity.class); update(); startActivity(myIntent); mySQLiteAdapter.close(); } } }); ```