I don't know how to pass data between my fragments "books" and "reservedBooks" in a viewPager which is an object of my class "bookCard" and part of my recyclerView to add it to the other recyclerView in my fragment "reservedBooks" throught the click of a button "reserve" that is part of each member of the recyclerView
You need a static place for storing data for any type of your data(books and reversedbook) you can use static array or database android
Then every time that you select an item , this item must remove from books in that staic array and add to another static array for reversedbook,
And every time that you replace fragment in view pager, you must update recyclerview by notifydatachanged()
Related
I'm developing an android app and I have a fragment that contains TextView & ListView in it. The list view has custom list items that contains two buttons. I want to make 'onClickListener' for one of those two buttons in my custom adapter class to change the text of the TextView, but I can't access it by findViewById() every time I try I got null exception.
My guess is that you're trying to access the TextView from inside of the Adapter.
If so, then you won't be able to get the TextView and it's normal to get a nullpointer exception.
The findViewById inside your adapter only finds the views that you have inflated in the getView() method of your adapter.
What you can do here is probably use an interface that's implemented by your Fragment to pass the information from your adapter back to the fragment.
This answer might be a good starting point : How to create interface between Fragment and adapter?
Hi guys i need some help in java im trying to make a recyclerview that have some items and i wanted whenever someone clicked on one item it took him to the other recyclerview but with the data i set it for ?? PLS HELP
if you want to send the data in this specific item.
in the recyclerview class
the list of the items presented in the recyclerview declare them as global variables.
and you will find this method
public void onBindViewHolder(Holderclass holder, final int position)
you can use this position variable to access that specific item in the list.
for example if you have arrayList "list" then.
list.get(position).
save the data in bundle and use putextra() to send it if it is a new intent or setarguments() if it is a new fragment, and then retrieve the data via getextra() or getarguments() in the new activity or fragment. repeat what you did with the first recyclerview
I hope this helps
I have a main fragment that contains a viewpager. This viewpager gets the same secondary fragment (different from the main one) but with different parameters every time. Inside the said secondary fragment that is inside the viewpager, i have a recyclerview. Inside these recyclerviews are some fields that the user fills up. When the main fragment (the one that holds the viewpager) is closed (via a button click) i need to get the data from each recyclerview. How do i to that?
The best way to solve this problem is that implement interface which will give call back to activity holding these fragment and then from Activity pass it to fragment(main) and then use viewpager to get Fragment(secondry) and pass data.
Steps one would be implent interface which will give callback to activity and the get fragment from viewpager(Link for same)
I spent some time to google it, but didn't help.
I have a listview that contains an ArrayList.
Can I collect all data in array, show it in listView and delete array, but not update listView - so data will be on screen?
Yes until you scroll the list view to next visible item (or call notify item set change), then ListView ask adapter to provide object for example at 5th position and you will get ArrayIndexOutOfBoundsException or NullPointerException. So if you want to avoid that you have to copy your list elements to another ArrayList instance and pass it to your adapter.
arrayListMain.get(position).remove(arrayListChild.get(position));
notifydatasetchange();
arrayListMain is which arraylist your are use at setAdapter and arraylistChild is arrayList in your adapter
I am developing a Cinema App, but I want to use 2 RecyclerViews, one has successfully loaded, it contains the list of cinemas, then I want when someone taps on any of the Cinemas it loads another list of RecyclerView containing Movies.
How can I deal with 2 RecyclerViews?
Am new in Android. Below is the link to the sample of codes:
This is the link of the sample codes
RecyclerView Item to Load Another RecyclerView with Nested JSON
You have to options here:
The two recycler views are displayed on the screen at the same time.
This will imply the data in the 2nd recylcler view need the ability to change multiple times.
Add this code in your onItemSelectListener from your cinemaRecyclerView
Cinema selectedCinema = cinemas.get(selectedPosition); // This is the selected cinema from the CinemaRecyclerView;
moviesAdapter.updateMovies(selectedCinema.getMovies);
In your MovieAdapter class add the following method.
public void updateMovies(List<Movie> movies){
this.movies.clear();
this.movies.addAll(movies);
notifyDataSetChanged();
}
The cinema recycler view is on one screen and the movies list is on the next screen.
Here you will need to pass the selected Cinema object to the next Activity/Fragment. Based on this selection you can directly instantiate your MoviesAdapter with the correct movies list.