I have a very simple question. I'm working on an Android application where I make use of Simple Adapter for ListView. Now I need to append items to this ListView dynamically. I know it is possible to do so in case of Array Adapters.
It is done as follows:
adapter.notifyDataSetChanged();
Is there any equivalent for the same in case of Simple Adapters? I couldn't find much relevant links regarding this on the net.
Kindly help.
Thanks in advance!
I think not, but you always can create a new SimpleAdapter and call setAdapter again with the new adapter.
If you are going to add/remove elements you, probably, need some other adapter not a SimpleAdapter. Because they say in the docs that SimpleAdapter is 'An easy adapter to map static data to views defined in an XML file'
Related
Is it possible for setting more than one adapter to a single list?
For example
list.setAdapter(adapter1);
list.setAdapter(adapter2);
Maybe you can try attaching multiple adapters to a single adapter like here
android attaching multiple adapters to one adapter
Or maybe this
http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/
if I understand what you need it for correctly
Pls update why you want it for so we have a better understanding
Can anyone tell me what exactly does an array adapter do? I've tried searching the net but all I get is code examples. Please explain me what it does, I've visited the android developers as well.
An ArrayAdapter can be used as a data source for a number of different Android Views, such as a ListView or a Spinner.
Basically, you pass some kind of array or list to the constructor of an ArrayAdapter. Then, the adapter can be hooked up to a ListView by calling setAdapter(). You can also use the add and remove methods of the adapter to modify the underlying list itself.
You can also use an ArrayAdapter to customize the appearance of items in a ListView for example (or other Views) by using the constructor and passing in the resource of a layout to use, or by overriding the getView() method and building it yourself.
Typically, an adapter is some kind of translator. It's the "man in the middle" who know how to dialog with both sides and convert what is said.
An arrayAdapter is a class which get datas from an array and format it for a listview or spinner to understand it. When a listview need the data 4, for example, it will ask the adapter who will return him the 4 element of the array.
Ok, the listview could directly use the array.But with the adapter you're allowed to use any kind of data source. An ArrayAdapter(subclass of adapter) uses an Array, but another adapter could use a database or a file or anything else.That way the listview is able to get datas directly from any source without knowing how to access it.That is the adapter's role.
Am trying to implement chrisbane's pull-to-refresh library for my ListView (https://github.com/chrisbanes/Android-PullToRefresh). It seems simple enough but what Im having trouble with is the fact it seems to require it's own data set, seperate to what's managed by your list adapter, i.e.
mListItems = new LinkedList<String>();
mListItems.addAll(Arrays.asList(mStrings));
All the examples I've seen just use this simple list of strings, but how do you go about using this with any kind of custom adapter, such as one that that contains a string and an imageview, etc?
There're plenty of examples on this site and around.
You create your adapter and set this arraylist as a field there
or usually set as a constructor parameter.
You #override getView() of this adapter and get your items using position parameter
in the getView(). Here look at the OrderAdapter class in this example:
http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/
and here at the GameAdapter class
http://jnastase.alner.net/archive/2010/12/19/custom-android-listadapter.aspx
hope this helps abit
I'm using a view that supports list inside another list. I want to multi-thread it and also use Endlessadapter with it.
This view, has its own adapter. How do I pass the data, that I get to this adapter to Endless adapter. All are in the same name-space. I don't think so I'm very clear with the question, but I'm also rather confused with my own architecture. I'll shape the question a bit better if I get some help. Thank you!
I think you should use:
Expandable ListView adapter
http://developer.android.com/reference/android/widget/ExpandableListAdapter.html
http://techdroid.kbeanie.com/2010/09/expandablelistview-on-android.html
Problem with expandable list adapter
I know my question isn't formulated well.
I'm adding items to an ArrayList downloaded from JSON file and the ArrayList is passed to a ListView.
So what is my problem?
After displaying the data from the ArrayList i wan't to add new items to it so they can be show right after they are added. I managed to do this by setting the Adapter for the ListView again after the data is added.
Displaying the new items should look smooth but instead it looks very sluggish and i know it's not the right way to do this.
I've searched about this problem but couldn't manage to find anything, so for anyone answering
Thanks in advance.
Its very easy
You need not to set the data adapter again to the listview..
instead
call after you downloaded the new data
listView.getAdapter().notifyDataSetChanged();
this function will tell the view to be build again.
In addition Check the following link. here i mentioned a complete code to use listview properly.
Using this we can achieve any listview behavior. We can embed animation also.
Change ListView background - strange behaviour
Hope this help :)