Just for reference I am been trying to follow the answer to this question
Basic Communication between two fragments
I have 2 Fragments
within a ViewPager
Adapter
along with an Actionbar
.
What I have is one fragment produces some data which can (if chosen) inserted to an SQLite table.
The second Fragment
simply displays all data in the table, however I am trying to make some communication that as soon as Fragment
1 inserts data into the SQLite
table. Fragment
2 is called to refresh its select query (as in do the query again) to automatically show the latest data. At the moment this is manually done with a button which I feel is not great.
This is my interface
in Fragment
1
onNumbersSavedListener mCallback;
public interface onNumbersSavedListener
{
public void RequestQueryRefresh();
}
@Override
public void onAttach(Activity activity) {
// TODO Auto-generated method stub
super.onAttach(activity);
try
{
mCallback = (onNumbersSavedListener) activity;
}
catch(ClassCastException e)
{
e.printStackTrace();
}
}
This is the main Activity
which contains the ViewPager
and implements the interface
public class MainActivity extends FragmentActivity implements TabListener, GenerateFragment.onNumbersSavedListener
This is the main problem I am having which I do not have IDs for the fragments which answer referred in the link stated above does so.
@Override
public void RequestQueryRefresh() {
// TODO Auto-generated method stub
}
TLDR: I am just looking for an easy and clean way for as soon as Fragment
1 saves into DB, fragment 2 updates its list view by re-running its query.