public void onCreate(Bundle savedInstanceState)
{
teachersData=new TeachersData(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList<Data> classid=teachersData.listClass();
ArrayAdapter<Data> adapter = new ArrayAdapter<Data>(this, android.R.layout.simple_list_item_1, classid);
setListAdapter(adapter);
public void onClick(DialogInterface dialog, int id) {
String className = edit.getText().toString();
teachersData.insert(null, className, 0, 0, null);
Toast.makeText(getBaseContext(), className + " Added.", Toast.LENGTH_LONG).show();
dialog.cancel();
}
})
I presume it involves notifyDataSetChanged() from my searching so far but I can’t figure out how to implement it.
You call
notifyDataSetChanged()at point you have updated the data and you want to display the new data. When you have the new data you doadapter = new ArrayAdapter<Data>(this, android.R.layout.simple_list_item_1, classid);(again) which means you are feeding the adapter with new data, and then you callnotifyDataSetChanged()to makeListViewrepopulate with the new data.