What is the alternative for android:entries in code? - android

How to I send an String array to a listView from the code and have the emulator display it?

That is a very general question... but the basic idea would be to create one of the usual Adapters, ArrayAdapter possibly in this case, initialize it with the String array and then call the ListView's setAdapter() method with that ArrayAdapter.

Related

Is there a simple list widget in android that lets me select from a list without having to create an adapter?

I have a list, I want the user to select one. It's a string. Maybe even have an Object I can associate with it.
Is there any way to do this without creating a subclass with an arrayadapter?
I see tons of examples and they all seem overengineered for what must be the most basic list handling problem in the world. Is there no default simple list string handler built in?
If there is, I can't find it.
Help?
Is there no default simple list string handler built in?
ListView is a simple list string handler that's built in.
Is there any way to do this without creating a subclass with an
arrayadapter?
You don't have to subclass ArrayAdapter to use it. Binding the data to ListView is one line of code:
final ListView list = ...;
list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data));
In your case, data would either be a List<String> or a String[].

Pass hashmap to array adapter in Android

I just want to pass a hashmap to array adapter in android. It is not going to be used for display. It is for some manipulation purpose. For display already a arraylist is passed.
Suggest how to just pass hashmap to adapter ?
Thanks in advance.
two possibilities
Add a parameter to the Constructor
create a setter
of course you have to write your own subclass of ArrayAdapter

Editing ArrayLists in Android ListView

I have an ArrayAdapter that's using an ArrayList to display data in a ListView.
During the course of the activity, I sometimes need to edit the ArrayList by adding and deleting items.
Is there a difference if I call the add/delete functions on the actual ArrayAdapter vs. the underlying ArrayList? Which is better to use?
Use the adapter methods. This will automatically notify your adapter (and thus the bound list) that your data has changed.
Some times it is necessary (or at least more convenient) to modify the ArrayList (e.g., is a field of some other class, or it is being modified by other thread that does not know about the adapter).
In those cases, you will need to call adapter.notifyDataSetChanged()

AutoCompleteTextView, ArrayAdapter and notifyDataSetChanged()

I'm using an AutoCompleteTextView with an ArrayAdapter which works like supposed.
The problem is, that I have to change the Array with the Autocomplete-Values. Calling notifyDataSetChanged() doesn't help. No changes are shown.
Do you know something to get around this problem?
Do not modify the ArrayList and call notifyDataSetChanged() as it will have no effect on ArrayAdapters (implementation seems broken).
Use clear(), add(), insert(), and remove() directly on your ArrayAdapter instead of those methods on your ArrayList.
You need to add more details to the question but based on a guesstimate of you problem, I would say that there is some problem in the implementation.
notifyDataSetChanged() informs the view to reload the data. If the data set up methods in the ArrayAdapter reference an unchanged data entity, notifyDataSetChanged() will have not effect.
A custom adapter implementation that extends ArrayAdapter will generally have an internal data structure that is the source of data for the adapter and which will contain the AutoComplete values you require.

Passing information between views

I am new to android programming, but I am trying to learn. I have written some code that takes in some parameters through a "normal" view with checkboxes and textviews. Then I use this information to generate a lot of numbers that I want to display in a listview. I have managed to create a listview when I press a run button, but how do I pass the information from the main view to the listview. Is it best to pass the information one number at the time or a large array with all the numbers. The list of numbers can be really large.
What you probably what to do is create an adapter with the numbers as the data source. If the numbers are in an array you can create a new ArrayAdapter and set the ListView adapter as that adapter:
ArrayAdapter adapter = new ArrayAdapter<Double>(getApplicationContext(), R.id.id_of_textbox, arrayOfDoubles);
listView.setAdapter(adapter);
In this code I've assumed the numbers are doubles, however ArrayAdapter is a generic class so it can be any object contained in the array. The array can also be presented as a List (like an ArrayList).
Hope that helps you out. Here are some bit of documentation to read and some good video sessions to watch:
ArrayAdapter
ListView.setAdapter()
The World of ListView Google I/O 2010 Session
How big is the array can get?
Most likely that displaying the list as another activity and passing the data as intent's extra will be the solution.

Categories

Resources