Questions tagged [android-arrayadapter]

A concrete BaseAdapter that is backed by an array of arbitrary objects.

From the documentation of the ArrayAdapter class:

A concrete BaseAdapter that is backed by an array of arbitrary objects. By default this class expects that the provided resource id references a single TextView. If you want to use a more complex layout, use the constructors that also takes a field id. That field id should reference a TextView in the larger layout resource.

However the TextView is referenced, it will be filled with the toString() of each object in the array. You can add lists or arrays of custom objects. Override the toString() method of your objects to determine what text will be displayed for the item in the list.

To use something other than TextViews for the array display, for instance, ImageViews, or to have some of data besides toString() results fill the views, override getView(int, View, ViewGroup) to return the type of view you want.

Tag Usage:

4383 questions
240
votes
7 answers

What is "android.R.layout.simple_list_item_1"?

I've started learning Android development and am following a todolist example from a book: // Create the array list of to do items final ArrayList todoItems = new ArrayList(); // Create the array adapter to bind the array to the…
Zakaria
  • 14,892
  • 22
  • 84
  • 125
200
votes
4 answers

"ArrayAdapter requires the resource ID to be a TextView" XML problems

I am getting an error when trying to set my view to display the ListView for the file I want to display(text file). I am pretty sure it has something to do with the XML. I just want to display the information from this.file =…
PeterL
  • 2,141
  • 3
  • 15
  • 15
179
votes
6 answers

notifyDataSetChanged example

I'm trying to use in my Android Application the notifyDataSetChanged() method for an ArrayAdapter but it doesn't work for me. I found as answer here, that notifyDataSetChanged() should run in the main thread, but there was no example for…
Tima
  • 12,765
  • 23
  • 82
  • 125
135
votes
11 answers

How can I update a single row in a ListView?

I have a ListView which displays news items. They contain an image, a title and some text. The image is loaded in a separate thread (with a queue and all) and when the image is downloaded, I now call notifyDataSetChanged() on the list adapter to…
Erik
  • 5,681
  • 8
  • 31
  • 32
122
votes
5 answers

Android ListView headers

I have ListView that has some kind of events on it. Events are sorted by day, and I would like to have header with date on it for every day, and then events listen below. Here is how I populate that list: ArrayList crs = new…
Rohit Malish
  • 3,209
  • 12
  • 49
  • 67
107
votes
9 answers

How does the getView() method work when creating your own custom adapter?

My questions are: What is exactly the function of the LayoutInflater? Why do all the articles that I've read check if convertview is null or not first? What does it mean when it is null and what does it mean when it isn't? What is the parent…
GrowinMan
  • 4,891
  • 12
  • 41
  • 58
102
votes
6 answers

What's the difference between BaseAdapter and ArrayAdapter?

I want to know the difference between using BaseAdapter and ArrayAdapter. I have been achieving what I want through ArrayAdapters. Does it affect the performance of the ListView on the adapter interface in which it is implemented ? And, the last…
Chintan Soni
  • 24,761
  • 25
  • 106
  • 174
101
votes
1 answer

Unable to modify ArrayAdapter in ListView: UnsupportedOperationException

I'm trying to make a list containing names. This list should be modifiable (add, delete, sort, etc). However, whenever I tried to change the items in the ArrayAdapter, the program crashed, with java.lang.UnsupportedOperationException error. Here is…
Ryan
  • 1,013
  • 2
  • 7
  • 4
96
votes
4 answers

Using a ListAdapter to fill a LinearLayout inside a ScrollView layout

I'm facing a very common problem: I layed out an activity and now it turns out it should display a few items within this ScrollView. The normal way to do that would be to use the existing ListAdapter, connect it to a ListView and BOOM I'd have my…
Stefan Hoth
  • 2,675
  • 3
  • 22
  • 33
75
votes
5 answers

Android custom Row Item for ListView

I have a ListView that should have the following layout in its rows: HEADER Text HEADER should be static but the Text changes every few seconds. I implemented it by populating a String[] array, pass it to an ArrayAdapter and set it every time the…
67
votes
4 answers

Difference between getView & getDropDownView in SpinnerAdapter

When you implement SpinnerAdapter you get getDropDownView, how does it differ from getView which you have when you need to extend BaseAdapter.
Win Myo Htet
  • 5,377
  • 3
  • 38
  • 56
63
votes
8 answers

ArrayAdapter in android to create simple listview

I tried to create an Activity in Android, This Activity only contains a ListView nothing else. As I know to fill the listview we need to use an ArrayAdapter. So to understand the ArrayAdapter I have read the following…
Nirav Kamani
  • 3,192
  • 7
  • 39
  • 68
57
votes
4 answers

What is the benefit of ViewHolder pattern in android?

When you are developing an Android program; and you want to have a ArrayAdapter you can Simply have a Class (most of times with ViewHolder suffix) or directly inflate your convertView and find your view by id. So What is the benefit of using…
57
votes
9 answers

android: smoothScrollToPosition() not working correctly

I'm trying to smoothly scroll to last element of a list after adding an element to the arrayadapter associated with the listview. The problem is that it just scrolls to a random position arrayadapter.add(item); //DOES NOT WORK…
54
votes
4 answers

How can I set onClickListener on ArrayAdapter?

I'm making class like as below // All necessary imports are here public class More extends Activity { String[] MoreItems = { "Transfers", "Budgets", "Branches", "Tools", "News", "Customer Service", "Settings", "Help", "About" }; …
Chatar Veer Suthar
  • 15,541
  • 26
  • 90
  • 154
1
2 3
99 100