I have a fragment class that contains a ListView and I have my own custom layout for the list, The process of adding something on the list is, within the fragment there is an add button, this button when clicked will open DialogFragment then passes data into SQL, everything works fine but the ListView does not refresh when something is added. I have been using adapter.notifyDataSetChanged();
How can I refresh the ListView?
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_notes, container, false);
add = (Button) view.findViewById(R.id.addbtn);
db = new dbhelp(getActivity());
db.open();
add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mydialog dialog = new mydialog();
dialog.show(getFragmentManager(), "Dialog Fragment");
}
});
populateList(view);
return view;
}
private void generateList(View view){
Cursor cursor = control.getdata();
CustomAdp adapter = new CustomAdp(getActivity(), cursor);
listView = (ListView) view.findViewById(android.R.id.list);
listView.setAdapter(adapter);
}