Multiple lists in one ListView - java

I have a series of buttons that I would like the user to press in order to show a different list in the list view. Say, button one brings up list one. User adds a few items to list one and then presses button two to open list two; user then adds a few items to that list.
How would I go about having multiple list that share a single list view? Also, how would I have the data of one list be saved so when the user switches lists... they can switch back to the original and have their items still presented in the list?
Thank you!

I guess what you are looking for is ExpandableListView
here is an example too

You could have multiple lists stored in some type of array. A list could be used for each list, and then when you are setting the listview's adapter, pass the current list object. Of course, after each item is added during the adding process(when user is adding items) you would need to add the items to the list, and then reset the listview. And as long as you kept the lists in context the entire time they would not be GarbageCollected. Once the user is done with the lists, you would need to save the lists somehow, unless this is just a temporary context where everytime you revisit the page it shows the default value for the lists.

Related

Android ListView Math equation Interface

I want to program an activity where a user has an input interface to enter three different values(an equation) and a listView to display them.
My current app uses an arraylist in which(with arraylist.add) a new value gets added. With adapter.notifydatasetchanged() the standart adapter is updated and the list view changed.
But my programme needs to have 2 additional features:
getter Functions on the listView in order to later use the entered data
the possibility to delete an entry in the list by for example pressing it
One approach of mine would that there should be a function that's the opposite of Arraylist.add() in order to delete an element from the data shown in the list view(I wouldn't need getter Functions from the ListView) But in order to delete a certain element I would still need to know which element was clicked...
Although this should not be such a special problem I haven't found a good solution for this specific problem so any kind of experience is appreciated:D...
Thank you very much
You can add do this with 2 approach:
1.Delete at once's - Means add a Delete button in each item of list and by click of that button you can delete that data item from ArrayList and then notify Adapter to refresh ListView
Also you can add deleted Item in separate ArrayList for your record which items was deleted so you can use this for your further business operations .
2.Delete Bulk data- For this add CheckBox in each item of list and by click of that button you can add that data item in separate ArrayList for selected items for deletions. And When you want delete add some delete button on header or bottom of ListView you can delete selected Data Items from ArrayList of Initial Data list and notify Adapter to refresh ListView.

How to create a list with data tables as items that can be sorted

What I want to create
I want to create a list where each item in that list is an data table like below: The user needs te be able to sort items in the data table and needs to be able to sort the data tables itself.
Each table is going to represent a client and each item in that table is an order. The user will then collect the orders, if he collected an order the order wil dissapear but the user is also able to bring them back.
What I tried
I tried to put a Recyclerview inside a Recyclerview but this caused unitended side effects and bugs, also I read online that it is basically a bad practice. My initial intention was to use a recylcerview with a sortedlist.
I did some searching online and a lot of people recommended using categories between items so that you only need one list. But because I have data tables (CardViews) that can be independent sorted this isn't an option.
If anyone want to give me a nudge in the right direction, I would be really thankful.
What you can do you can use recycler view and in custom row check box with 8 text views and when position is 0 inflate categories like fat, calcium etc and after that position populate data and if you want next button which shows next items in list use fragments or pagination that should do the trick and you can achieve this using single recycler view. You can also use header to show categories.

items from listview to which field and how?

I have 2 list view filled with items in it. I want to take those items, and display them in something like this, for example:
item1+item2+item3
all separated with "+". However, I don't know what I should put this(textview, listview?) considering I need to be able to retrieve those elements (item1+item2+item3) to another (text or listview?) after. And also I'm not quite sure of how to add the items from that listview to another field separated by a "+"? I'm a beginner in java/android.

Android: How to clear a list view without removing data from the array list?

I am attempting to create a list view which displays different data based on a selection from an a spinner.
My list view is implemented via a base adapter which works fine.
My data is stored in an array list of objects which each contains fields that store individual data and based on the selection from the spinner filters the data stored in the array list and displays it on the list view.
But my question is how can I clear a list view content without clearing its underlying data (stored in the array list) and calling notifyDataSetChanged? I want to be able to preserve the data stored so if the user goes back to a previous selection, the data is still present.
Thank you for your time in reading this.
As your data is stored into an ArrayList, you can simply use:
listView.setAdapter(null);
It will remove the adapter of your ListView, and so, remove all the items displayed.
The data will still be in your ArrayList so if you want to re-display this ListView, you just have to recreate your Adapter and set it again. You can even create a global instance of your BaseAdapter so you only have to create it once.
You could just pass another ArrayList to the adapter with the new data to show inside the ListView.
Or, you could create two ArrayList inside the Adapter, one named original which contains the original elements of the ListView and another currentElements which will be the real ArrayList to show changed as you want. With some custom methods, you can choose to switch between the two versions of the ArrayList.
It's could be the same concept of an Adapter which implement a Filter.
Anyway if i understand your problem, you want to change the content of a ListView based on the selection. Well, in this case i would send another ArrayList to show.
Create a list of adapters, one adapter for each selection. Then simply switch to a different adapter when the selection is changed with listView.setAdapter(adapter)

How to reference a position in a Set?

How can I reference a position within a Set? Like with an array: array[5];
I am developing an android soundboard that has a favorites tab. The favorites tab uses a listview . When a user adds a favorite, the text of the button is added to the set. Now I have setup a contextmenu for the list view to allow the user to delete an item by long pressing, and pushing delete. The context menu passes the position of the list view that triggered the context menu and I am trying to delete that position.
You cannot. Sets have no notion of order, but concrete implementations may.
However, all sets implement toArray(), and
If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
What's your underlying data structure?
You can't - a Set does not have indexes for its elements. You have two options, depending on your requirements:
use a SetUniqueList from commons-collections, if you want the properties of Set in a List
use Iterator (and a foreach loop) if you want to iterate the Set

Categories

Resources