I'm trying to update my WebView in a Fragment when RecyclerView Item is clicked. In the debug console it's printing my hard-coded URL, but it's not updating the View - it is staying on "Google" webpage without any changes, but seems like onClickListener is working.
MainActivity.java
public class MainActivity extends AppCompatActivity {
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Add Websites
ArrayList<Website> websitesList = new ArrayList<>();
websitesList.add(new Website(R.drawable.ic_launcher_background, "Line 1", "https://google.com/"));
websitesList.add(new Website(R.drawable.ic_launcher_background, "Line 2", "https://yahoo.com/"));
websitesList.add(new Website(R.drawable.ic_launcher_background, "Line 3", "https://abv.bg/"));
mRecyclerView = findViewById(R.id.recyclerView);
mLayoutManager = new LinearLayoutManager(this);
mAdapter = new WebsiteAdapter(websitesList);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
}
public void switchContent(int id, Fragment fragment) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(id, fragment);
ft.commit();
}
}
RecyclerView Adapter
#Override
public void onBindViewHolder(#NonNull ExampleViewHolder holder, int position) {
final Website currentItem = mWebsiteList.get(position);
holder.mImageView.setImageResource(currentItem.getImage());
holder.mTitle.setText(currentItem.getTitle());
holder.mTitle.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
fragmentJump(currentItem);
}
});
}
#Override
public int getItemCount() {
return mWebsiteList.size();
}
private void fragmentJump(Website mItemSelected) {
Fragment mFragment = new WebsiteView();
Bundle mBundle = new Bundle();
mBundle.putString("url", "http://facebook.com/");
mFragment.setArguments(mBundle);
switchContent(R.id.fragment, mFragment);
}
public void switchContent(int id, Fragment fragment) {
if (mContext == null)
return;
if (mContext instanceof MainActivity) {
MainActivity mainActivity = (MainActivity) mContext;
mainActivity.switchContent(id, fragment);
}
}
WebView Fragment
private WebView webView;
String mUrl;
public WebsiteView() {}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_website_view, container, false);
try {
mUrl = getArguments().getString("url");
} catch(Exception ex) {
System.out.println(ex.toString());
mUrl = "http://google.com/";
}
System.out.println(mUrl);
webView = v.findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(mUrl);
return v;
}
Okay, it appeared that I'm actually trying to update the Fragment data, and when I replace another fragment with my desired one it works. Any ideas how to update the WebView in the fragment?
Related
Not able to pass the retrived list of data from retrofit to a recyclerview in fragment!
Tried some solutions but not working!
I have tried creating methods in fragment and passing but not working!
Getting null!
Activity
TabLayout tabLayout;
ViewPager viewPager;
RecyclerView recyclerView;
//vars
private Dto dto;
List<Post_DTO> post_dto_list=new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState)
{
dto=new Dto();
UpdateList();
super.onCreate(savedInstanceState);
setContentView(R.layout.home_layout);
tabLayout=(TabLayout)findViewById(R.id.tabLayout);
viewPager=(ViewPager)findViewById(R.id.viewPager);
tabLayout.addTab(tabLayout.newTab().setText("Dashboard"));
tabLayout.addTab(tabLayout.newTab().setText("Converations"));
tabLayout.addTab(tabLayout.newTab().setText("Profile"));
PostFragment pf=new PostFragment();
pf.passData(getApplicationContext(),post_dto_list);
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
//ft.add(R.id.posts_recyclerview, ft);
ft.addToBackStack(null);
ft.commit();
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
final MyAdapter adapter = new MyAdapter(this,getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
System.out.println(tab.getPosition());
viewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
private void UpdateList() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(getString(R.string.postUrl))
.addConverterFactory(GsonConverterFactory.create())
.build();
PostsInterface postsInterface =retrofit.create(PostsInterface.class);
Call<Post_DTO_Resp> call= postsInterface.getPosts();
call.enqueue(new Callback<Post_DTO_Resp>() {
#Override
public void onResponse(Call<Post_DTO_Resp> call, Response<Post_DTO_Resp> response) {
//pDialog.dismiss();
if(!response.isSuccessful())
{
Toast.makeText(getApplicationContext(),"Loading the posts!",Toast.LENGTH_SHORT).show();
}
Post_DTO_Resp posts = response.body();
post_dto_list=posts.getPost_dto_list();
//dto.setList(post_dto_list);
}
#Override
public void onFailure(Call<Post_DTO_Resp> call, Throwable t) {
//pDialog.dismiss();
if(t.getMessage().equals("End of input at line 1 column 1 path $"))
{
Toast.makeText(getApplicationContext(), "There are no posts!", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(), "Api Error!", Toast.LENGTH_LONG).show();
}
}
});
}
}
Fragment!
public class PostFragment extends Fragment {
RecyclerView recyclerView;
View v;
Dto dtobject;
private static final String DESCRIBABLE_KEY = "list";
private Describable mDescribable;
List<Post_DTO> post_dto_list;
public PostFragment() {
// Required empty public constructor
}
public void passData(Context context, List<Post_DTO> list) {
//mContext = context;
post_dto_list = list;
// mIndex = pos;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
v=inflater.inflate(R.layout.fragment_posts, container, false);
recyclerView=(RecyclerView) v.findViewById(R.id.posts_recyclerview);
RecyclerViewAdapter recyclerViewAdapter=new RecyclerViewAdapter(getContext(),post_dto_list);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(recyclerViewAdapter);
//listupdater();
return v;
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
Just want to get the post_dto_list from Activity to fragment class!
Suggestions please!
You can use a bundle to pass a list from activity to fragment.
In activity:
Bundle bundle = new Bundle();
bundle.putSerializable("list", mList);
mFragment.setArguments(bundle);
And then in your fragment:
mList = getIntent().getExtras().getSerializable("list"));
But the POJO that your list contains should be parcelable ( Parcelable better than Serializable).
Your POJO should be something like:
public class MyPOJO implements Parcelable {
For more info refer this.
Here is my adapter
viewHolder.Edit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(final View view) {
mAuth=FirebaseAuth.getInstance();
FirebaseFirestore firebaseFirestore=FirebaseFirestore.getInstance();
firebaseFirestore.collection("bookings").whereEqualTo("customer",mAuth.getUid())
.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
#Override
public void onComplete(#NonNull Task<QuerySnapshot> task) {
for (DocumentSnapshot document : task.getResult()) {
currentUserId=document.getId();
Log.d("ID", String.valueOf(currentUserId));
}
StylistFragment servicesFragment = new StylistFragment();
AppCompatActivity activity = (AppCompatActivity) view.getContext();
Bundle bundle=new Bundle();
bundle.putString("userdocumentid",currentUserId);
servicesFragment.setArguments(bundle);
activity.getSupportFragmentManager().beginTransaction()
.replace(R.id.frameLayout, servicesFragment).addToBackStack(null).commit();
// change navigation item color of a fragment when button is clicked
((HomeActivity)view.getContext()).changeMenu(R.id.navigation_stylist);
}
});
}
});
this is my fragment where i am receiving value from third fragment to first fragment
public class StylistFragment extends Fragment {
private RecyclerView recyclerView;
private String docid;
CircleImageView stylistImg;
public StylistFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view= inflater.inflate(R.layout.stylist_recycler, container, false);
recyclerView=view.findViewById(R.id.stylistRecycler);
stylistImg=view.findViewById(R.id.stylistImg);
Bundle bundle=getArguments();
if(bundle!=null){
docid=bundle.getString("userdocumentid","");
Log.d("selectedDocumentId",docid);
}
try{
FirebaseFirestore db = FirebaseFirestore.getInstance();
try {
db.collection("stylist").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
#Override
public void onComplete(#NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
try {
ArrayList<String> stylistId=new ArrayList<>();
for(DocumentSnapshot documentSnapshot:task.getResult()){
String id=documentSnapshot.getId();
stylistId.add(id);
}
StylistAdapter listAdapter = new StylistAdapter(task,docid,stylistId,stylistImg);
RecyclerView.ItemDecoration dividerItemDecoration = new DividerItemDecorator(ContextCompat.getDrawable(getContext(), R.drawable.divider));
recyclerView.addItemDecoration(dividerItemDecoration);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(listAdapter);
}catch (Exception e){
e.printStackTrace();
}
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
}
});
}catch (Exception e){
e.printStackTrace();
}
}catch (Exception e){
e.printStackTrace();
}
return view;
}
}
I am passing value from third fragment to first fragment.In third fragment i am using recyclerview if recyclerview excutes first item the value is available which i am getting in docid but if it executes more than one time the docid is null.Earlier i used the same code its worked fine i don't know what happend its not working now
Make use of interfaces.
Make a interface inside the third fragment and implement it in first fragment and call the function from third fragment with the value.
you can use the value in first fragment.
public class MainActivity extends AppCompatActivity {
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, StylistFragment.getInstannce("navigation_home")).addToBackStack(null).commit();
return true;
case R.id.navigation_dashboard:
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, StylistFragment.getInstannce("navigation_dashboard")).addToBackStack(null).commit();
return true;
case R.id.navigation_notifications:
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, StylistFragment.getInstannce("navigation_notifications")).addToBackStack(null).commit();
return true;
}
return false;
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
}
public static class StylistFragment extends Fragment {
private static final String TAG_VALUE = "tag_value";
public static StylistFragment getInstannce(String myValue){
Bundle extras = new Bundle();
extras.putString(TAG_VALUE,myValue);
StylistFragment fragment = new StylistFragment();
fragment.setArguments(extras);
return fragment;
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final String myStringValue = getArguments().getString(TAG_VALUE);
Log.d(TAG_VALUE, "My passed Value: " + myStringValue);
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
return super.onCreateView(inflater, container, savedInstanceState);
}
}
Output
D/tag_value: My passed Value: navigation_home
D/tag_value: My passed Value: navigation_dashboard
D/tag_value: My passed Value: navigation_notifications
MainActivity has 2 buttons and when I click the buttons I want 2 fragments to appear in the same page.But when I click on itsMeContact button, it comes up, but when I click on the PhoneContact button, I overwrite the other one.
MainActivity.java
public class MainActivity extends AppCompatActivity {
Button itsMeContact,phoneContact;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
itsMeContact= (Button) findViewById(R.id.its_me_contact);
phoneContact= (Button) findViewById(R.id.phone_contact);
itsMeContact.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
FragmentManager manager = getFragmentManager();
UserFragment userFragment = new UserFragment();
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.frame_layout, userFragment, "userFragment");
transaction.commit();
}
});
phoneContact.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
FragmentManager manager = getFragmentManager();
FragmentB fragmentB = new FragmentB();
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.frame_layout, fragmentB, "fragg");
transaction.commit();
}
});
}
}
UserFragment.java
public class UserFragment extends Fragment {
RecyclerView recyclerView ;
UserAdapter userAdapter ;
ArrayList<Person> arrayList ;
private LinearLayoutManager layoutManager;
Button itsMeContact,phoneContact;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_user,container,false);
recyclerView = view.findViewById(R.id.recycler_view);
itsMeContact= view.findViewById(R.id.its_me_contact);
layoutManager = new LinearLayoutManager(getActivity());
layoutManager.scrollToPosition(0);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
arrayList=new ArrayList<Person>();
initial();
return view;
}
private void initial() {
Factory.getInstance().user().enqueue(new Callback<List<User>>() {
#Override
public void onResponse(Call<List<User>> call, Response<List<User>> response) {
// textView.setText(response.body().get(0).name);
userAdapter= new UserAdapter(response.body(), getActivity());
recyclerView.setAdapter(userAdapter);
}
#Override
public void onFailure(Call<List<User>> call, Throwable t) {
}
});
}
}
FragmentB.java
public class FragmentB extends Fragment {
TextView textView;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_fragment_b,container,false);
textView=view.findViewById(R.id.textView);
textView.setText("naber");
return view;
}
}
Your advice important for me !
Thank you very much
My app:
enter image description here
Each Fragment transaction you did use the same framelayout : "R.id.frame_layout".
So this is normal if "it looks overhead". If you want 2 fragments displayed in a same layout, you should use 2 differents framelayout.
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 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