can i delete array of listView but not update listview? - java

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

Related

How to select all items listed in Recyclerview using androidx.recyclerview.selection?

I am using androidx.recyclerview.selection for selecting items in a RecyclerView.
I am trying to build an edit fragment in which it pre-populates the old views in the RecyclerView. At present, I was able to load the old values from API call and update the adapter's list by notifyDataSetChanged call. But I want all the items in list to be selected in other words I want to add all items somehow to SelectionTracker object somehow while the fragment loads.
Whenever notifyDataSetChanged is called I could see SelectionTracker's observer onSelectionRefresh() is triggered but I couldn't update the selection tracker there since it is going on infinite call loop.
SelectionTracker.setItemsSelected:
selectionTracker?.setItemsSelected(listOfKeysToBeSelected, true)
val size = documents.size
for(number in 0 until size){
(tracker as SelectionTracker<Long>?)?.select(number.toLong())
}
pass all position of recyclerview using for loop start with 0 to total count of single item.
You select every item in the RecyclerView adapter by iteration.
Assuming your key is Long:
for (i in 0 until recyclerAdapter.itemCount)
selectionTracker.select(i.toLong())

Invisible listview item row

i want to implement a search Text to listView,
i load the listView items from server.
Currently, everytime that user enters something to the searchText i remove all items in the listView and add them again to the listView (if they contain the user entered string)
However it takes alot of time, to remove the whole listView and then start reload all items to list again
Therefore i want to loop all over the listView and to invisible the un-matched rows, is it possible? (something like View.GONE)
for example, i want to invisible the k-th item row in listView.
Also, i will want to change this item row to visible again.
thanks alot
you don't need make the view invisible. Have a EdiText at the top. Then have filter for your listview and display items in listview accordingly. call notifydatasetchanged method to refresh listview.
An example of search on listview.
http://www.androidhive.info/2012/09/android-adding-search-functionality-to-listview/
An example of listview with custom filter can be found in the link below
Search in ListView with EditText

Android ListView not showing newly added items and erasing old items when switching content views

I have a custom listview defined in my xml layout file. I can add items to this ListView inside onCreate method, through an array adapter.
However when I add items from another content view and then go back to the content view with the ListView all the items are gone and there's nothing listed. Even after calling .notifyDataSetChanged();
It seems like I can only add to the list when the content view containing the ListView is currently being displayed. Is this the default behavior?
Failed attempted workaround
I used another array to keep the newly added items and then try to add them when the ListView became visible again. I had to override onContentChanged() to do so but then no items were added still.
So the main question is
How can I dynamically add items to the ListView even if it's out of sight and still preserve the old items?
PS: I have to say the Android API is one of the worst I've ever come across.
If you change content view, then all the previous views are going to be destroyed. Are you using an adapter? If so, then it would be very easy to add all the items to the list again.
There shouldn't be any reason to setContentView any time other than in onCreate.
If you were looking to have multiple screens, instead of changing content view, then start a new activity.
dynamically add items:
//add at the top of the list
mListView.addHeaderView(itemView);
// add at the bottom of the list
mListView.addFooterView(itemView);

Change the text in a listview base adapter

I have a custom baseadapter that i use to populate a listview. each row that populates contains 4 text views in it. How can I change the text of one of these views without having to repopulate a brand new array into the adapter?
Just change the value into the array and call this method
youradapter.notifydatasetchanged()

to get checked items from listview and store it in array

I am new to android..please help me.
how to get the checked items from listview and store it an array and display it in another listview in the next layout in the same activity?pls help....
Hi if you are using listView with check box then you can follow this
linkhttp://appfulcrum.com/?p=281
Rather than create checked list box, create custom list view. You can easily detect whether checked box is checked or not.

Categories