I have a Page which has three buttons (teens, adult, old) and same page contains view pager which has 7 tabs for week days. When this page loaded it show list of all programs for all (teens, adult and old) categories in all 7 tabs according to which day is. What I want to implement is that when user select anyone one of the above button the contents of all the tabs populated by new filtered data list according to the selected button.
How I can implement this?.
You just need to set the selection in your Adapter and then call notifyDataChanged. That will reload the adapter and go back through the instantiateItem calls again. In instantiateItem you can look at the selection and change the content accordingly.
Related
I thought long and hard about how to represent this problem. I thought that there is too much code but that I can describe it simply. And that this will probably tip someone off as to where the problem may be.
Android Studio 3.5.1.
I have created a simple AppCompatActivity that loads a new Tab whenever the user presses a "+" button in the menu. The PagerAdapter loads a new fragment with a ListView backed by a SimpleCursorAdapter. This test code loads the Table (TabID, Name, Count) with dummy data for 20 rows hooks it up and displays the data. So far so good. One Tab loaded with a ListView of dummy data showing Name and Count in the ListViewItem layout file. Cool. Wired up an onItemClick event for the ListView in the Fragment, so that when the user clicks on a row, the count is incremented in the database for the correct TabID, then I refresh the Cursor, call adapter.changeCursor() followed by adapter.notifyDataSetChanged(). This works beautifully. Every tap on a row increments the count on the row and displays it.
Now, I click "+" to add my second Tab. A new tab appears, dummy data is loaded, and the count field is at zero for each row. I can swipe left/right back and forth between the tabs clicking rows and incrementing counts. The counts are maintained and displayed correctly.
Here is where the problem starts. I click "+" again to add the third Tab. It is loaded with dummy data and count field set to zero. Good. Swipe back to Tab #2 and all the fields I incremented remember their counts. Swipe back to Tab #1, however, and all the counts are lost! Back to zero. Go to Tab #2, all the counts are there. Go to Tab #3, and all the counts are back to zero. It seems that if I have 3 or more Tabs, and go back and forth between adjacent Tabs; no problems. But if I Tab from 1 to 3, counts in Tab #1 are lost; and vice versa, if I Tab from 3 to 1, counts in Tab #3 are lost.
I hope I have made this as clear and concise as possible and that someone knows why this might be breaking on Tab #3 +.
I have implemented a recyclerview. On clicking a item it would display the related field of that item (eg. name, age).
Now i want to make two buttons prev and next to show the details of previous and next item without going back to the list (in same activity). How can i do that?
From my understanding you want to implement ViewPager. Check ViewPager
Here is the tutorial.
I have a view pager with two tabs in my app (A and B). The first tab i.e A has a listview. Clicking on any of the items in the list opens a new fragment (let's call it C) with another list. The tab B also has a listview.
The list in tab B and the list contained in the fragment C have the same type of items. That is each item of both list is of the same class. I have used a recycler view with a custom adapter to create the list. Since both lists in tab B and fragment c are of the same object type I have used the same adapter, namely (CarListAdapter.class) for this purpose.
The problem I am facing is that when I open fragment C then go back to tab A and then right swipe so that tab B is visible, clicking on an item in tab B causes null pointer exception, reason being that the list in fragment CarListFragment.class still has the data from fragment C and not tab B.(However the list is rendered properly, it is only the click that is not working properly)
Since two instance of this adapter are present I expected this to work fine. If however I use two different adapters with exact same code like (CarListAdapterC.class and CarListAdapterB.class) the code works fine.
I am stuck, can someone please explain why this is happening?
I have encountered same problem when using view pager and recycler view. I have searched allot and as i know it's an issue in recycler view adapter.
As you may know view pager load one more next page by default every time it shows a page.and here is where adapter shows the problem.The different instances of a same adapter that you create point to same place.because of that it still has other pages items.
I know it's not a good idea but i have created another adapter same as the first one with different name and used it for the next list and it worked.try to separate your list's adapters.let me know if it works.
I finally found the solution, it was really stupid on my part. I had static fields in RecyclerView Adapter. Removing them worked like a charm.
I'm making a simple notepad app. In one fragment there's a list view of added notes and when some note is selected the other fragment shows the details of that note. Now if user clicks delete button a note is deleted, but how do I refresh the list view and detail view accordingly?
For refreshing the ListView actually what you have to refresh is the underlaying Adapter.
This would be the workflow of your scenario:
Remove the selected item
Call notifyDataSetChanged()
Set another item as the current one, for example the previous note or the first one.
And that's it.
I'm building this application where I have 2 activities. Both of them consist of 3 fragment - one for title, one for content and one for tab control. It is shown at image below.
First activity serves for showing list of some data's headers (item name etc.), search, app info etc. When user presses item in list, app takes him to another activity to show him detail of chosen item. This "details" activity has 6 different content fragments and user switch between them via buttons in tab control fragment (I did switching between content fragments by showing chosen one and hiding all others - I don't know if it's right way, it's my firs app so it came to my mind at first :) ).
And what I would like to do is: When I'm in detail and I swipe left/right then I want app to take me to previous/next item's detail, to same fragment where I currently was in (so not to next content fragment, but to detail of next item in 1st activity's list).
Is this somehow possible please? Because I have totally no clue how to do it :)
And what I would like to do is: When I'm in detail and I swipe
left/rigt then I want app to take me to previous/next item's detail,
to same fragment where I currently was in (so not to next content
fragment, but to detail of next item in 1st activity's list).
If you want to swipe left-right then you would need a ViewPager widget. I'm not sure how should your details activity behave so I'm providing you with two options. Do you want to be able to switch to the next/previous item's details only when a certain fragment is the one currently viewed by the user(from the 6 content fragments, which I assume are related and show various data for a single item)? If yes then in that desired fragment you would replace the current content of the fragment(which will only act as a container) with a ViewPager and use nested fragments for the actual content. If the user switches to the details of a previous/next item's details and then suddenly wants to see the data for that item from one of the remaining 5 content fragments then you would need to have some updates method on them to refresh the data to show the current item(a OnPageChangeListener will be useful here).
Second option, is if you want to allow the user to swipe left/right from any of the 6 content fragments. If this is the case you would use the same method as above but you'll modify each of those 6 fragments.
Showing the next/previous item is easy, just get some sort of identifier of the data(a position, id), retrieve the whole used data(as in the first activity) and then cycle between it.