I have one fragment, which is a list of database values. I use ListView to display values ββon screen.
I have another snippet containing buttons for adding records to the database. So my problem is that when I add a record to the database by clicking the button on the first fragment, I need a second fragment (or second page in the application) to update the list of database values ββthat are displayed on the screen.
Here is a snippet of the database list:
public class FragManage extends Fragment { private PunchesDataSource datasource; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { datasource = new PunchesDataSource(getActivity()); datasource.open(); List<Punch> values = datasource.getAllPunches();
So I just want to do adapter.notifyDataSetChanged () in another fragment that contains buttons (something like this):
// Punch OUT button. Button out_button = (Button) myFragmentView.findViewById(R.id.out_button); out_button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { datasource.createPunch("out-" + getTime()); FragManage.adapter.notifyDataSetChanged(); } });
source share