开发者

Passing information between views

开发者 https://www.devze.com 2023-01-12 07:45 出处:网络
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 t

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 displa开发者_JAVA技巧y 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号