I want to make a list of SMSs in my own application..
my question is about the steps makes by the adapter (automatic)
-when new message arrived I adds it to list object (not the ListView).
-then I passes the list to the adapter of the listView.
the adapter GetView() method run for every Item in the list
-I notify the listview about the change.
- the listview re-draws all its existing rows and then draw the new row.
My question: this behavior (re-draw and redraw, it mean every row will be drown times equal to the total rows) affect the performance?
*if the question is not clear I say: does the ListView Draw all the Raws just to add new row? *
The ListView doesn't redraw every single item in order to add one. It will only be drawn when you scroll to it. And yes you have to notify ListView that the change had happened.
I guess you want to add the item at the top position. So all other item's position and index will change . Adapter will redraw the whole list(only elements which are visible on the screen) .
For performance you can use viewHolder pattern.
see this link
[Making ListView Scrolling Smooth][1]http://developer.android.com/training/improving-layouts/smooth-scrolling.html
Related
The usual thing when I insert a new row into a ListView it is added at the bottom of the ListView by default. Can I make it upside down? I want the new added rows be on top, or I may say I want the ListView in descending flow sorted by time.
Is there a way to implement that from ListView settings? or it is related to the List connected with the ListView?
I searched about it and all I could find is "stackFromBottom" which makes the view of ListView scroll down and start showing from the bottom, and it is different from what I want.
you can add row to top using add function with index.
example :
items.add(0, obj)
inside adapter you have item list that you add the row to top(index 0) and call
notifyiteminserted or notifydatasetchanged
probably duplicated
Add new items to top of list view on Android?
You can do it in several way
1.You can use Collections Feature. After add item in your List then call Collections.reverse() then update your ListView
2.You can set your List to add(0,value) 0 no position then update your ListView
Hi I have run into a design issue and can't figure out the best approach to take. Here is a sample of what I am trying to achieve:
When the user clicks on the Plus icon another row will be added below the current condition. Currently the condition row is in a listview and is setup using a custom adapter. The left col is filled with the options that the user has chosen from the select columns view. All that is working but I can't seem to figure out how to add a new row. So is there a way to dynamically add a new row to the list and fill it with the same data? OR is there a better alternate way to set this up?
So your custom adapter is starting off with three rows? Then when the user clicks on the plus icon, the onClick listener should call a method on your adapter that sets some kind of indication that there are now four rows (after which it calls notifyDataSetChanged()). And your getView() method should look at that indicator and if position == 2 (third row) and the indicator is not set, it returns an "Order By" view. If the indicator is set, then it should return a "Condition View" and only return an "Order By" view when position == 3 (fourth row). Does that make sense?
Your adapter reflects the state of your list model at any moment in time. Any event that occurs where you want to change the ListView should update some kind of state in the adapter. Then getView() should always check that current state when returning a view. So always think in two phases:
Your event (like onClick) updates some model data in the adapter somewhere.
Your adapter's getView() method always checks the current model data in the adapter to figure out how to set up the view for the given position.
I have a ListView with custom_row , every row has a textView1 and a textView2 , the list has now 2 records , and i have a button that is not on the list.
When i click the button i want to get the text from textView2 of the 2 records.
Is it possible?
I would take a shortcut, you ListView is being populated by an Adapter that uses a dataset. This dataset can be almost any datastructure such as Array, ArrayList, etc.
The layout you define, such as custom_row in you case only defines the structure of your view i.e. "where" items will show within on item on the list.
On the other hand, it is still your responsibility to tell the ListView "what" to show within the textView1 and textView2. You do this using the Adapter which connects the ListView to the dataset. More often than not, the ListView is a one-to-one mapping of the dataset i.e. the first item on the list is the first item in you dataset (I don't know what you are using for only two items, might be an array).
The ListView calls getCount() on the Adapter to find out how many total views there will be. It then call getView() for each view to be shown on the screen. It is in this method that you define what will actually show in a single view on the list (your custom_row).
Now you would know which entry of the dataset is supposed to populate which view in the ListView so you can just read it off there. For example, if your getView() does:
textView2.setText(getItem(position).getSomeTextField());
And the original dataset is an ArrayList named listDataSet
You could just do listDataSet.get(2).getSomeTextField()
NOTE: You will have to manage the scope of the dataset so that it's visible from wherever you are calling.
Get back your ListView (maybe already stored in an object thanks to findViewById, or by calling getListView() on your ListActivity).
Then call getItemAtPosition() on your list view, with the position you want.
I want to set a simple listener in a ListView so when the user passes through the 50º item of the list, I call a thread that will append 100 more items into that list.
I am looking for an event to do that for over an hour now and I don't seem to be able to find one. There are tons of events for when a list item will be clicked or something like that, but I can't find one for when the user simples passes through the item in the scroll processing.
Thank you so much in advance!
Put the ScrollListener on list view, when it reaches end of the list u will get the last item, then add the progressbar at the footer and then start thread where u can load the other items, and notifyDataSetChanged() for adapter , and you will get the list with added items..!!
And you can check whether the item number 50 is reached, in onScroll().
I think there is no need to do this, because the ListView recycles the item views. So you dont occupy memory for the listview items (per each value), you just use memory for the ArrayList(or any data type you use for feeding).
Also you can do this whenever user reaches the end of the listview (last listview item) then refeed the adapter with the new value and then call .notifyDataSetChanged().
About reaching 50% of listview visible items can make things scrambled because you'll always have the 50% reached, otherwise you can improvise (reaching 50% on the ArrayList instead ListView) by checking if more than 50% of the existing ArrayList is displayed, let's say you 10 items and the 6th item is on the listview count / 2, you check if the on that half listview item is more than 50% of data feed for the listview you feed with new data. (I might be unclear)
I hope the idea will help you.
BACKGROUND:
I have a grid of 36 buttons, lets say a 6 rows & 6 columns numbered 1 to 36, displayed 2 rows at a time via a GridView and custom Adapter
The grid displays fine, and all of the scrolling works properly.
QUESTION:
I want to be able to click on an item, have it removed from the grid and the remain items shuffle up into place. Currently I am able to disable the item disabled, set its visibility to INVISIBLE or GONE, but none of these will actually remove it from the display.
Suggestions?
Specifically, you need to remove the corresponding object from the data set of the underlying adapter and then call adapter.notifyDataSetChanged(). This isn't going to provide you with an animation, though, if that was part of this question.
It may be interesting to try a tween animation for the item in question and then finally remove it from your adapter at the end. I'm not well-versed in animation, so I'm not sure how well this will work in an AdapterView.
You should be able to update the adapter, and then call notifyDataSetChanged to force the grid view to be updated.