tags:

views:

41

answers:

2

Hi

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.

A: 

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:

matto1990
I was planning to make the listview as an intent. Is that not necessary? Because when I start the new intent it is a bit more difficult to pass the information to it.
Anders
In that case what you should do is either package the array into the intent using intent.putExtra("arrayKey", arrayVariable) and then at the other end getIntent().getIntArrayExtra("arrayKey"). The other option is to add the information to the database and then query it in the listview activity to get a cursor to use in the adapter. The first method seems to be what you are after
matto1990
A: 

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.

Asahi