How to disable RecyclerView Adapter when Recyclerview is Invisible - android

Hi I have two recyclerview in my app. I am loading data and fill the recyclerview with it. at bottom i have one button , lets say when user load the app, first recylcerview is visible, now user click on bottom button I am hiding first recyclerview and make second recyclerview visible. so now issue is Toast messages of first recyclerview's adapter is still appears even it is hide state.
I do not want to show Toast messages of first recyclerview when it is hide.
recyclerViewfirst.setVisibility(View.VISIBLE);
recyclerViewsecond.setVisibility(View.GONE);

Please follow these steps :
No need for setting visibility for RecyclerView.
Pass Empty ArrayList to your adapter and set adapter to RecyclerView.
Adapter mAdapter;
ArrayList<String> mList = new ArrayList<>();
mAdapter = new Adapter(context, mList);
recyclerViewsecond.setAdapter(mAdapter);
When data is there in ArrayList simply notify the adapter.
mAdapter.notifyDataSetChanged();

Don't pass any data for first RecyclerView when you click the button. That is you can display RecyclerView again with empty data.

no needs to hide the recycle view
just reset the adapter with another array list and notify the adapter
then first list data will replace with another list data

Related

adapter on click listener with a filterable recyclerview android kotlin

I just created a filterable recyclerView of an adapter with textview.onTextChangedListener in my project. it worked just fine. unfortunately, this has caused a problem with my adapter click listener. since I implemented set on click listener to my adapter by taking adapter position when we click on an item in adapter recyclerview it will get the adapter position and pass the item values like text and image to textview and image view respectively.
The filtering method I created is to filter items in adapter recyclerview by userName. so when I type to search for a name, the recyclerview will display the matching one but when I click on that matching name it passes the wrong item values to my textview and imageview. it always passes the first item of adapter recyclerview. I guess that maybe the adapter always takes the 1st position of the adapter dataset since after filtering the only matching item will display. I have tried a lot but I still have no idea to solve this problem.

How can i transfer info recyclerview to another recyclerview and back

How can i transfer data one recyclerview to other recyclerview an activity and back.
When click one recylerview element it is showing another recyclerview and invisible clicked recyclerview element and opposite this prosess
enter image description here
simply remove item by using notifyitemremoved(pogition);
to first list of adapter and copy the item content.
then insert item to another recyclerview list adapter by
notifyiteminserted();
hope this will solve your problem;

updating adapter by data from ListView (not the opposite)

I have a long ListView, which its items are editable (simple strings).
The user can change the content as he/she wants.
My problem is, that when I want to retrieve the new data from the List view,
I can not reach the invisible items in the list.
How can I retrieve the data from these items without scrolling to these items?
Is there a way to fill the adapter ,with the new data the user entered to the list?
I think you can do that. if you have reference of Adapter for that list view
you can call getCount and then iterate and while calling getItem(pos) , to get data for all the positions in the list view.

add more to listview with out calling notifydataset

im trying to create a feed like instagram. When the user reaches the bottom of the listview more pics should be added to the listview. Is there a way to add more to the listview with out calling notifyDataSetChanged() because it causes the listview to flicker.
Try creating a new Adapter or re-initializing the Adapter being used with added data then set that Adapter to the ListView.
Then use setSelection(int position) to move to the bottom of the ListView.

List view postion comes to top after append data

I have a list view that fetch data from server when it scroll to bottom. once the data received it pass to the adapter via an array list.
But when i set the array list values to adapter, it appends the data and automatically the position moves to top.
Could some one tell me what is the problem occured here?
I guess that you recreated new Adapter and set it to your listview.
If you do like that, your listview will scroll to top.
To keep your listview item position, just call mAdapter.notifyDataSetChanged(); after update your array list.
Hope it can help you!

Categories

Resources