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.
Related
I would like to click on an item of a listview to show another listview of other items, what can I do?
in my application I have a main Activity, where I have inserted a bottom view navigation, when you click on an item in the bottom view menu, the corresponding fragment appears in the main activity.
my listview is in the first fragment, and in the same fragment the next screen must appear, after the click in the listview.
do I have to replace the fragment of the listview with another one or can I replace only the listview? how?
Thanks for the attention
Instead of those options (replacing the fragment / list view), you could use the onItemSelected method to repopulate the list view object with the new list. Since you already know how to do this, it would seem the simplest option. A simple switch statement would suffice.
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 ListView that represents a list of folders and when I click one item, I want to load another list that shows the content of this folder. How can I link these views together and to be able to go back to the first one with the back button ?
Well, since you didn't provide a code in your question, I will try giving an answer in a descriptive manner.
You can use fragments to do this. Your base Activity's layout must have a fragment container which you will use to display your fragment containing the first ListView data. Once after you click on a cell, you call the constructor of the second ListView, and replace the current content of the fragment container with the newly created fragment.
You may implement a back feature by implementing an ArrayList in your Activity and appending the fragments into that array list as the user navigates through the list. onBack pressed you can call the top most fragment from that Array list and assign it to the fragment container.
This should work well, given there are not too many types of ListViews that you may want to implement.
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.
I have one grid view in one activity.I have set Adapter using array-list.
Gridview is displaying the list of the items stored in the database.Let say it is some products.
When i click on any product in the grid-view it will navigate me to product detail screen.
From product detail screen i can delete product.If i delete product and press back button it will navigate me to product list screen.
Expected: Product list screen will come without deleted item.
Actual: Product list screen is coming with deleted item. When touch this item it will do nothing.
Supporting my question,please see below picture
You have get gridview items from db in OnResume method of activity. And when u delete any item and then back press, it will call OnResume method of previous activity where u get new list, and call notifyDataSetChanged() on the grid, in order to recreate the view
Try Some like:
if (homeGridViewDatas.size() > 0) {
homeGridViewAdapter = new HomeGridViewAdapter(activity, context,
homeGridViewDatas);
gvHome.setAdapter(homeGridViewAdapter);
homeGridViewAdapter.notifyDataSetChanged();
}
You should notify the gridadapter which something is changed by callingnotifyDataSetChanged on it. In onResumeshould be ok. Or when you update it too.
When i click on any product in the grid-view it will navigate me to
product detail screen.
When you go from gridView activity (product list screen) to detail activity(product detail screen.), the detail activity is launched on top of your gridView activity in Stack.
If i delete product and press back button it will navigate me to
product list screen.
And when you delete a particular product in detail screen and press back button, the detail activity is removed from the stack and hence the gridview activity which was below detail activity comes to foreground and becomes visible.
Product list screen is coming with deleted item. When touch this item
it will do nothing.
However your gridView activity still has the previous data.Hence it displays that old data and nothing happens on touch as actual data is different than the one in adapter.
Solution :
You need to notify the adapter for gridView in that activity, that the data has been changed and the view must be updated accordingly.
As onResume() is called everytime activity comes to foreground and is visible, it is the better place to call notifyDataSetChanged() on your gridadapter.