android


Object as a source for the listview


I have an object submission which contains some informations which I would like to show in a list view.
For example, in my object I can do this:
submission.firstElement().getDate()
and
submission.firstElement().getTitle()
which returns me a date and a title.
My problem is: how to show those two elements (not only the first's) in a listview (two elements per list item).
I have thinked on a for loop with the submission.size() but I have no idea how to get forward with.
Thank you for your help.
You'll want to look at using a ListView and a ArrayAdapter. You could use a BaseAdapter but I have found a ArrayAdapter more than adequate for displaying a list of custom objects in a ListView.
First create a layout that will be used to show the desired data per row in the ListView. In your case I assume that it will be two TextViews, one showing the title and date.
Once done, create a ListAdapter and in it's constructor give it the layout for the row created above. Once done, use the getView() function to access the layout and populate the TextView's with the object's date and title.
Have a look at the following links:
http://developer.android.com/reference/android/widget/ArrayAdapter.html
http://developer.android.com/reference/android/widget/BaseAdapter.html
http://www.vogella.de/articles/AndroidListView/article.html
EDIT:
Ana, to aid you a bit further use a ListActivity as shown in this Google documentation: http://developer.android.com/reference/android/app/ListActivity.html. In the example given they use a SimpleListAdapter. However, for an ArrayAdapter the constructor is a little simpler:
new ArrayListAdapter(this, R.layout.row_layout, listOfObjects);
When using a ListActivity a layout does not need to be created as by default it includes one.

Related Links

Get the (several) EditText values from list view and post as an array
Cannot Remove View From WindowManager - Multiple Threads
Two Picture and 5 textview overlapping in list view with relative layout
How to know Specificaly Name of the running apps in android?
FragmentActivity causing activity leaks (IntentReceiver) but not on MapActivity
Android layout dynamically issue
android - LinearLayout (Horizontal) - auto space between items
How to pass mp3 file from one activity to another as an intent
Android Application Lifecycle and back button
Unable to open debugger port : java.net.SocketException “Socket closed”
Youtube upload videos programmatically
Using Git/SCM as Application Persistence Layer
How to disable the list-item which I've just clicked in an listview in android?
Android MediaRecorder Multiple Files
How can I fix errors about imports in this code?
Can tinyXML-1 open files on Android?

Categories

HOME
github-for-windows
hessian
jwplayer
rom
vxml
big-o
google-admin-sdk
opengl-3
mql5
distribution
shared-libraries
symmetricds
vuejs
cfml
oledb
replication
guzzle
string-concatenation
pchart
mongoid6
maze
android-things
bioinformatics
browser-sync
mql
python-2.6
hibernate-validator
wacom
card.io
indy10
getlasterror
video-capture
docfx
graphhopper
connection-pool
c9.io
azure-arm
signal-strength
procfile
automapper-5
clarifai
jquery-ui-draggable
globalize
netbeans6.8
tf
azure-cli
truezip
lsyncd
rackspace-cloud
universal-analytics
cd-burning
cvxpy
builtins
redbeard-ios
iotivity
installshield-2010
dimension
firebase-security
query-by-example
turbo-prolog
phpwebsocket
beanstalk
exim4
ascii-art
file-move
toolkit
slash
jdk1.7
rdflib
cwrsync
beatsmusic
addressing-mode
functional-java
memset
dot42
extjs2
openargs
notorm
kendo-dataviz
gpars
joomla-template
virtual-pc
apache-abdera
nokia-s40
uimanageddocument
vfs
usertype
predicatebuilder
infobright
user-tracking
winmain
qglwidget
timertask
zen
purepdf
google-wave
software-lifecycle
fault-tolerance
wspbuilder

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App