Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Tim Cooke
paul wheaton
Sheriffs:
Paul Clapham
Liutauras Vilda
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Piet Souris
Himai Minh
Bartenders:
Forum:
Android
How do I update the particular list item in RecyclerView
Debdeep Ganguly
Greenhorn
Posts: 18
I like...
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Here is my EditListItemsFragment.java which supports a separate fragment to edit the list items
@Override public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_edit_list_item, container, false); mUnbinder = ButterKnife.bind(this, view); // Retrieving Bundle contents mBundle = getArguments(); if (mBundle != null) { // Log.d(TAG, mBundle.toString()); mInformation = mBundle.getParcelable("Information"); // Log.d(TAG, mInformation.name.toString()); fullNameEdit.setText(mInformation.name.toString(), TextView.BufferType.EDITABLE); descriptionEdit.setText(mInformation.description.toString(), TextView.BufferType.EDITABLE); dobEdit.setText(mInformation.dateOfBirth.toString(), TextView.BufferType.EDITABLE); genderEdit.setText(mInformation.gender.toString(), TextView.BufferType.EDITABLE); } else { Toast.makeText(getActivity(), "No data in bundle", Toast.LENGTH_SHORT).show(); } refreshButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String name = fullNameEdit.getText().toString(); String description = descriptionEdit.getText().toString(); String dob = dobEdit.getText().toString(); String gender = genderEdit.getText().toString(); Information information = new Information(name, description, dob, gender); // getting position of view clicked in DataListFragment setOnItemClick int position = mBundle.getInt("pos"); updateListItem(information, position); getActivity().getSupportFragmentManager().popBackStack(); } }); return view; } private void updateListItem(Information information,int position) { mFragmentListAdapter.notifyItemChanged(position); }
Here's my DataListFragment.java containing the recyclerview list items
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.data_list_fragment, container, false); return view; } View.OnClickListener mOnClickListener=new View.OnClickListener() { @Override public void onClick(View view) { Information information = data.get((int)view.getTag()); // Putting recycler view list items data into bundle here mBundle = new Bundle(); mBundle.putParcelable("Information", information); mBundle.putInt("pos",(int) view.getTag()); FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); fragmentManager.beginTransaction().replace(R.id.relative_layout_container, EditListItemsFragment.instantiate(getActivity(),EditListItemsFragment.class.getName(),mBundle), EditListItemsFragment.class.getName()).addToBackStack(EditListItemsFragment.class.getName()).commit(); } }; private void setAdapter() { if (mFragmentListAdapter == null) { data = new ArrayList<>(); mFragmentListAdapter = new FragmentListAdapter(getActivity(), data, mOnClickListener); } else { mFragmentListAdapter.notifyDataSetChanged(); } mRecyclerView.setAdapter(mFragmentListAdapter); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mRecyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view); mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); floatingActionButton = (FloatingActionButton) view.findViewById(R.id.myFAB); floatingActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentNewEntryPage fragmentNewEntryPage = new FragmentNewEntryPage(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.relative_layout_container, fragmentNewEntryPage, FragmentNewEntryPage.class.getName()); fragmentTransaction.addToBackStack(DataListFragment.class.getName()); fragmentTransaction.commit(); } }); setAdapter(); }
About that updateListItem(), how to implement it ?
Tim Moores
Bartender
Posts: 7488
171
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
What do you want to do that you can't do using the reference to the adapter, or by replacing the adapter with a new one based on the updated data?
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Multiple viewpagers in one fragment
1 Error needs fix - cannot make a static reference to the non static method
Error cannot be cast to android.app.Activity
MapFragment getMap( ) always returns null;
How can i get checkbox position into listview to remove corresponding textview
More...