I've been struggling for few days on this issue. My project is having 4 fragments which share the same floating button. I have managed to reference the fragments in order to allow the floating button to access each, however although I'm shifting between each fragment, it showing the position of the first one only. here's my code
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setNavigationViewListener();
//set the drawer layout and navigation view
mDrawerLayout = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem menuItem) {
//set item selected persist highlight
menuItem.setChecked(true);
//close drawer
mDrawerLayout.closeDrawers();
//set action as per the item selected
return true;
}
});
//create an adapter that knows where each fragment is
final LocationFragmentAdapter adapter = new LocationFragmentAdapter(this, getSupportFragmentManager());
mViewPager = findViewById(R.id.viewPager);
mViewPager.setAdapter(adapter);
adapter.getItem(position);
//set the function for the floating button to add a new item
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.i(LOG_TAG, "the current fragment " + adapter.getPageTitle(position));
if(position == 0) {
Intent intent = new Intent(MainActivity.this, EditorActivity.class);
startActivity(intent);
}
else if (position == 1) {
Intent intent = new Intent(MainActivity.this, RecipeEditor.class);
startActivity(intent);
}
}
});
}
this is my fragmentAdapter
public class LocationFragmentAdapter extends FragmentPagerAdapter {
final int count = 4;
private int [] tabTitle = {R.string.inventory_platform, R.string.product_platform, R.string.customer_platform, R.string.order_platform};
private Context mContext;
public LocationFragmentAdapter(Context context, FragmentManager fm){
super(fm);
mContext = context;
}
#Override
public Fragment getItem(int position) {
if(position == 0) {
return new InventoryFragment();
}else if(position == 1) {
return new RecipeFragment();
}else if(position == 2) {
return new CustomerFragment();
}else {
return new OrderFragment();
}
}
thats my InventoryFragment
#Override
public void onActivityCreated(Bundle savedInstanceState){
getActivity().getSupportLoaderManager().initLoader(STOCK_LOADER, null, this);
super.onActivityCreated(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState){
final View rootView = inflater.inflate(R.layout.activity_main, container, false);
//set empty activity
ListView listView = rootView.findViewById(R.id.display_view);
View emptyView = rootView.findViewById(R.id.empty_view);
listView.setEmptyView(emptyView);
//create a new cursor adapter
mCursorAdapter = new PlatformCursorAdapter(getActivity(),null);
listView.setAdapter(mCursorAdapter);
//create onClick listener to inflate the editor view
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//create new intent to opend the editor
Intent intent = new Intent(getActivity(), EditorActivity.class);
//create Uri to pass the contents of the item selected to the edit view
Uri currentItem = ContentUris.withAppendedId(StoreEntry.CONTENT_URI, id);
intent.setData(currentItem);
startActivity(intent);
}
});
getLoaderManager().initLoader(STOCK_LOADER, null, this);
return rootView;
}
and my RecipeFragment
}
#Override
public void onActivityCreated(Bundle savedInstanceState){
getActivity().getSupportLoaderManager().initLoader(RECIPE_lOADER, null, this);
super.onActivityCreated(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState){
final View rootView = inflater.inflate(R.layout.activity_main, container, false);
//set empty activity
ListView listView = rootView.findViewById(R.id.display_view);
View emptyView = rootView.findViewById(R.id.empty_view);
listView.setEmptyView(emptyView);
//create a new cursor adapter
mCursorAdapter = new RecipeCursorAdapter(getActivity(),null);
listView.setAdapter(mCursorAdapter);
//create onClick listener to inflate the editor view
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//create new intent to opened the editor
Intent intent = new Intent(getActivity(), EditorActivity.class);
//create Uri to pass the contents of the item selected to the edit view
Uri currentItem = ContentUris.withAppendedId(RecipeEntry.CONTENT_URI, id);
intent.setData(currentItem);
startActivity(intent);
}
});
return rootView;
}
I haven't created the last two fragments yet. Please let me know if you can find the error.
The log message is always showing the Inventory Fragment
You will have to update the position every time a page is selected using a pager listener
mPager.setOnPageChangeListener(new OnPageChangeListener() {
#Override
public void onPageScrollStateChanged(int arg0) { }
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) { }
#Override
public void onPageSelected(int position) {
this.position = position
}
});
Related
Hello I want to move to another activity from my fragment. I ve tried almost every solution which I found, but after I press button my app is instantly closed. I am new in java, and i guess i need some help.
public class GalleryFragment extends Fragment {
private GalleryViewModel galleryViewModel;
Intent intent;
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_gallery, container, false);
intent = new Intent(GalleryFragment.this.getActivity(), HomeFragment.class);
final Button btn = (Button) rootView.findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(intent);
}
});
galleryViewModel =
ViewModelProviders.of(this).get(GalleryViewModel.class);
View root = inflater.inflate(R.layout.fragment_gallery, container, false);
final TextView textView = root.findViewById(R.id.text_gallery);
galleryViewModel.getText().observe(this, new Observer<String>() {
#Override
public void onChanged(#Nullable String s) {
textView.setText(s);
}
});
return root;
}
}
I'm assuming from this line:
intent = new Intent(GalleryFragment.this.getActivity(), HomeFragment.class);
That you're trying to launch a Fragment, not an Activity. In order to transition to another Fragment, replace your Intent with:
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
getFragmentManager()
.beginTransaction()
.replace(...) //Or add, depends on your use case
.commit();
}
});
As noob developer im developing a flashcards app where i am populating cards using recyclerview. The issue is when i add a new card using a FAB, i refresh Main activity. Here i find that when i click on any card it doesnt display any data. Debugging revealed that the position of onClick(int position) in the recyclerview fragment adds on the previous size of the cards and thus im unable to see the data. How to get correct onClick position? Please help..
public class CardFragment extends Fragment {
public static List<String> QArray = new ArrayList<>();
public CardFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final OnSelectFlashListner mCallback = null;
// Inflate the layout for this fragment
final RecyclerView flashRecycler = (RecyclerView) inflater.inflate(R.layout.recy_view , container, false);
try{
SQLiteOpenHelper flashCardsHelper1 = new FlashCardsHelper(getContext());
SQLiteDatabase db = flashCardsHelper1.getReadableDatabase();
Cursor cursor = db.query("Flashdata",new String[]{"question", "answer"},null,null,null,null,null);
Log.d("Flash data", DatabaseUtils.dumpCursorToString(cursor));
if (cursor.moveToFirst()){
do {
QArray.add(cursor.getString(0));
}while (cursor.moveToNext());
}
cursor.close();
db.close();
}catch (Exception e){
e.printStackTrace();
}
flashAdapter flashAdap = new flashAdapter(QArray);
flashRecycler.setAdapter(flashAdap);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
flashRecycler.setLayoutManager(linearLayoutManager);
flashAdap.setListner(new flashAdapter.Listner(){
#Override
public void onClick(int position) {
Intent intent = new Intent(getActivity(),FlashCardOpen.class);
intent.putExtra(FlashCardOpen.EXXTRA_QUESTIONNO,position);
getActivity().startActivity(intent);
}
});
Button button = (Button)flashRecycler.findViewById(R.id.btn_Add);
return flashRecycler;
}
im refreshing the Main activity via FAB:
private void loadFAB() {
FloatingActionButton fab = (FloatingActionButton)findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.dialog_box);
dialog.setTitle("Add Flash Card");
final EditText textViewQues = (EditText)dialog.findViewById(R.id.et_dialogQuestion);
final EditText textViewAns = (EditText)dialog.findViewById(R.id.et_dialogAnswer);
Button btn_cancel = (Button)dialog.findViewById(R.id.btn_cancel);
btn_cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
Button btn_add = (Button)dialog.findViewById(R.id.btn_Add);
btn_add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
writeToDb(textViewQues.getText().toString(),textViewAns.getText().toString());
showNotif();
Intent intent = new Intent(context,MainActivity.class);
context.startActivity(intent);
dialog.dismiss();
}
});
dialog.show();
}
});
}
As it turned out, this was not the problem at all. I was populating an array list which kept on appending the whole list on top of previous one. i simply added the array.clear() at start of view onCreateView() and the problem was resolved.
Debugging rules!
I was looking answer in similar topics but nothing works for me. I have Activity which has a fragment. This fragment has adapter. Everything is fine even if I rotate screen, but when I rotate screen and try to update adapter (for example by sort items in adapter - method sort) I get NULL on adapter.
When Activity starts first time this is happening:
ON CREATE (ACTIVITY)
SETUP VIEW PAGER (ACTIVITY)
CONSTRUCTOR (FRAGMENT)
SET DATA IN ADAPTER (ACTIVITY)
ON CREATE (FRAGMENT)
CREATE ADAPTER (FRAGMENT)
ON CREATE VIEW (FRAGMENT)
UPDATE ADAPTER (FRAGMENT)
ON ACTIVITY CREATED (FRAGMENT)
In the second time when I rotate screen:
ON CREATE (ACTIVITY)
CONSTRUCTOR (FRAGMENT)
ON CREATE (FRAGMENT)
CREATE ADAPTER (FRAGMENT)
SETUP VIEW PAGER (ACTIVITY)
CONSTRUCTOR (FRAGMENT)
SET DATA IN ADAPTER (ACTIVITY)
ON CREATE VIEW (FRAGMENT)
UPDATE ADAPTER (FRAGMENT)
ON ACTIVITY CREATED (FRAGMENT)
So the problem is that in activity method super.onCreate(savedInstanceState) the fragment is recreated istelf. I was trying pass NULL for super.onCreate(null) and also checking if savedInstance is NULL, changing FragmentPagerAdapter for FragmentStatePagerAdapter, and many others things. What I want to do is save and get fragment, adapter in proper way or just make activity start everytime like in the first time.
PART OF MAIN ACTIVITY
public class MainActivity extends AppCompatActivity {
private TabLayout tabLayout;
private ViewPager viewPager;
SongsFragment songsFragment;
TabAdapter tabAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(null);
setContentView(R.layout.activity_main);
//init work
tabAdapter = new TabAdapter(getSupportFragmentManager());
songsFragment = new SongsFragment();
songsFragment.setData(database.getSongs(readOption(), readOrder()));
tabAdapter.addFragment(songsFragment, "TAB");
viewPager.setAdapter(tabAdapter);
tabLayout.setupWithViewPager(viewPager);
}
public void sort() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setItems(R.array.sorts, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if(which == 0) writeSort("number", "ASC");
else if(which == 1) writeSort("number", "DESC");
else if(which == 2) writeSort("title", "ASC");
else if(which == 3) writeSort("title", "DESC");
songsFragment.setData(database.getSongs(readOption(), readOrder()));
songsFragment.updateAdapter();
}
}).show();
}
}
FRAGMENT
public class SongsFragment extends Fragment {
private RecyclerView recyclerView;
List<Song> songs = new ArrayList<>();
SongsAdapter adapter;
public SongsFragment() {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v("TAG", "onCr");
if(!(savedInstanceState == null || !savedInstanceState.containsKey("list"))) {
songs = (List<Song>) savedInstanceState.getSerializable("list");
}
createAdapter();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.v("TAG", "onCrV");
View view = inflater.inflate(R.layout.fragment_songs, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.fragment_songs_SongsList);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(adapter);
updateAdapter();
return view;
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable("list", (Serializable) songs);
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
public void setData(List<Song> songs) {
this.songs = songs;
}
public void createAdapter() {
adapter = new SongsAdapter(getContext(), songs);
}
public void updateAdapter() {
adapter.clear();
adapter.addAll(songs);
adapter.notifyDataSetChanged();
}
}
FRAGMENT PAGER ADAPTER
public class TabAdapter extends FragmentStatePagerAdapter {
List<Fragment> fragments = new ArrayList<>();
List<String> titles = new ArrayList<>();
public TabAdapter(FragmentManager manager) {
super(manager);
}
#Override
public Fragment getItem(int position) {
return fragments.get(position);
}
#Override
public int getCount() {
return fragments.size();
}
#Override
public CharSequence getPageTitle(int position) {
return titles.get(position);
}
public void addFragment(Fragment fragment, String title) {
fragments.add(fragment);
titles.add(title);
}
}
I'm trying to simply put a logo on my ActionBar in android but nothing seems to be working. I have literally tried every solution I could find on this website and others without any luck. Any help would be appreciated,
Jacob
Here is my java:
public class Home extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setLogo(R.drawable.ic_launcher);
mNavItems.add(new NavItem("Home", "Find everything you need to know in one place", R.drawable.home_icon));
mNavItems.add(new NavItem("Learn About Our Programs", "Learn about what we do to help the city", R.drawable.list));
mNavItems.add(new NavItem("About Us", "Get to know about us on the personal level", R.drawable.info_circled_alt));
mNavItems.add(new NavItem("Contact Us", "Want to know more about something? Send us an email or phone call", R.drawable.questionm));
// DrawerLayout
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// Populate the Navigtion Drawer with options
mDrawerPane = (RelativeLayout) findViewById(R.id.drawerPane);
mDrawerList = (ListView) findViewById(R.id.navList);
DrawerListAdapter adapter = new DrawerListAdapter(this, mNavItems);
mDrawerList.setAdapter(adapter);
// Drawer Item click listeners
mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItemFromDrawer(position);
}
});
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_opem, R.string.drawer_close) {
#Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
invalidateOptionsMenu();
}
#Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
Log.d(TAG, "onDrawerClosed: " + getTitle());
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle
// If it returns true, then it has handled
// the nav drawer indicator touch event
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle your other action bar items...
return super.onOptionsItemSelected(item);
}
private void selectItemFromDrawer(int position) {
// Close the drawer
mDrawerLayout.closeDrawer(mDrawerPane);
Intent intent;
switch (position) {
case 0:
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(Home.this, Home.class);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(i);
overridePendingTransition(R.animator.animation1, R.animator.animation2);
}
}, 300);
break;
case 1:
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(Home.this, FindOpp.class);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(i);
overridePendingTransition(R.animator.animation1, R.animator.animation2);;
}
}, 300);
break;
case 2:
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(Home.this, About_Us.class);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(i);
overridePendingTransition(R.animator.animation1, R.animator.animation2);;
}
}, 300);
break;
}
}
}
class NavItem {
String mTitle;
String mSubtitle;
int mIcon;
public NavItem(String title, String subtitle, int icon) {
mTitle = title;
mSubtitle = subtitle;
mIcon = icon;
}
}
class DrawerListAdapter extends BaseAdapter {
Context mContext;
ArrayList<NavItem> mNavItems;
public DrawerListAdapter(Context context, ArrayList<NavItem> navItems) {
mContext = context;
mNavItems = navItems;
}
#Override
public int getCount() {
return mNavItems.size();
}
#Override
public Object getItem(int position) {
return mNavItems.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.drawer_item, null);
}
else {
view = convertView;
}
TextView titleView = (TextView) view.findViewById(R.id.title);
TextView subtitleView = (TextView) view.findViewById(R.id.subTitle);
ImageView iconView = (ImageView) view.findViewById(R.id.icon);
titleView.setText( mNavItems.get(position).mTitle );
subtitleView.setText( mNavItems.get(position).mSubtitle );
iconView.setImageResource(mNavItems.get(position).mIcon);
return view;
}
}
class PreferencesFragment extends Fragment {
public PreferencesFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_prefences, container, false);
}
}
This may help you , try this
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
I´m trying to udate a ListView in a Fragment the only way it actually will work is if I instanciate the fragment new. adpter.notifyDataSetChanged() is not working? Whay not? Here the Code an Activity and the Fragment:
public class TimerList extends Activity{
private DataSource datasource;
TimerListFragment timerfragment;
IntervalListFragment intervalfragment;
public List<TimerObject> values;
public String name;
public String intervals;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.interval_fragment_container);
datasource = new DataSource(this);
datasource.open();
values = datasource.getAllComments();
if (savedInstanceState == null) {
Toast.makeText(getApplicationContext(), "MADE NEW FRAGMENTS", Toast.LENGTH_SHORT).show();
timerfragment = new TimerListFragment();
intervalfragment = new IntervalListFragment();
}
}
public void delete(Long position){
TimerObject timerobject = datasource.getTimerObject(position);
datasource.deleteComment(timerobject);
values = datasource.getAllComments();
}
#Override
protected void onStart() {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.fragment_container, timerfragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
super.onStart();
}
And my Fragment :
public class TimerListFragment extends ListFragment {
List<TimerObject> values ;
Activity a;
ArrayAdapter<TimerObject> adapter;
ListView lv;
#Override
public void onCreate(Bundle savedInstanceState) {
setHasOptionsMenu(true);
values = ((TimerList)getActivity()).getValues();
setBar();
adapter = new ArrayAdapter<TimerObject>(getActivity(), android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
super.onCreate(savedInstanceState);
}
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
((TimerList)getActivity()).play(Long.valueOf(position));
super.onListItemClick(l, v, position, id);
}
public void setBar(){
ActionBar actionbar = getActivity().getActionBar();
actionbar.setTitle("Timer List");
}
public void update(){
setBar();
Toast.makeText(getActivity(), "UPDATE", Toast.LENGTH_LONG).show();
values = ((TimerList)getActivity()).getValues();
adapter.notifyDataSetChanged();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.interval_timer_list,
container, false);
return view;
}
#Override
public void onStart() {
update();
lv = getListView();
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView parent, View view, int position, long id) {
final TimerObject selected = adapter.getItem(position);
final Dialog d = new Dialog(getActivity());
d.setContentView(R.layout.interval_deletetimer_dialog);
d.setTitle("Delete " + selected.getComment() + "?" );
ImageButton delete = (ImageButton) d.findViewById(R.id.delete);
delete.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
((TimerList)getActivity()).delete(Long.valueOf(selected.getId()));
update();
}
});
d.show();
return true;
}
});
super.onStart();
}
I tried to do something similar, and I solved this problem by simply redoing the fragment transaction.
In your case, you could accomplish this within your onListItemClick() method.
you could copy this:
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.fragment_container, timerfragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
into your onListItemClick() method in your fragment
This resets the fragment. Unfortunately, this would also set your list to null. A way around this would be to make the values list a private static variable of the TimerListFragment class. That way, any changes made to the list will remain 'saved', and when you reload your fragment, it will be populated with the newly updated list.
hope this helps