Android ListView Math equation Interface - java

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.

Related

How to add item to a list then represint in a ListView from another list?

At the present, I have an EditText, so I can add whatever I want to add to a list, and then dynamically show in the ListView.
I want to restrict what item I add to the ListView. I was thinking about a database, where all the items stored. When I start to type something in the EditText, for example "Appl..." I want the app to suggest the items stored in the db, like "Apple", "Apple Pie" etc. And when I click on the "Apple" it should add to the ListView.
I know this is possible, since I already saw this in other apps, but I don't know what it's called or where can I see tutorials about it.

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.

Android - TextView in a Custom ListView loses its content while scrolling

I have came across these type of questions a lot, But none of the answers solved my problem.
I am developing a mobile shopping application model. I have a custom ListView with an ImageView, and EditText(quantity), 2 Buttons for increasing and decreasing the quantity, 3 TextViews one for item Name and other two for prices and I am dynamically loading a number of Buttons for NetWeights based on the requirement through Java code and I am implementing it using CustomAdapter(Class) extending BaseAdapter and getView().
Problem 1:
When I use the condition if(convertView==null), setTag(holder) and getTag(), the dynamically loaded Buttons are getting duplicated and gets doubled in number.
Problem 2:
While scrolling the custom ListView I am loosing my data on 2 of the TextViews while the other TextView(name) is fine because in that TextView I don't Change data on runtime. On the other two TextViews(prices) I change the data on runtime using ButtonClicks(increase and decrease) where at that time when I scroll the two TextViews, it looses its content. Actually I had this same problem with the EditText(displaying quantity), I solved it using the TextWatcher by getting the value and passing it in an array and again setting it. I used the same technique (i.e) the TextWatcher for the TextViews But that did'nt Help. I also tried removing the TextWatcher and setting the text with the array and adding TextWatcher. Still I am loosing my content in those TextViews
Any Suggestions??????
Problem 1:
While using ViewHolder (setTag(), getTag()) we will be reusing the views.
For example: Let's say we have 10 listview items and the screen can display 3 items at a time. Lets say we add 2 buttons to list item 1. First time when we load the listview we will see two buttons. Lets say now we scroll down and come back to the list item 1 again, as we are reusing the views, we already have 2 buttons and if we have the code to add buttons using getTag() then 2 more buttons will be added. I think this may be causing the issue of button duplication. To add little more information, list item 1, list item 4, list item 7 and list item 10 will all use same view, as our screen in this example can display just 3 items.
Problem 2:
One idea is to store all these text values in the arrayList.
For example, lets assume we have one textView inside each list item that can be incremented/ decremented. Set textWatcher on this textView and whenever text changes add it to the arrrayList using 'position' as the index. Inside getView method when you do getTag() try to set the textView using previously stored text (that was stored inside the arrayList)if exists.

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)

Multiple lists in one ListView

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.

Categories

Resources