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

Prevent Joda-Time to print negative numbers
Getting email from Facebook - FB android SDK
Pick an image and save it in custom folder
Android Insistent Notification Interrupted By SMS - How to make uninterruptable?
Android: Send notifications to all users
Android: Hiding soft keyboard when touching out of EditText
Appcompact EditText give Error on click of Cursor
No design library issue
coronasdk sqlite copy database to computer from device
Upload video to google drive using android api
Android ObjectAnimator+ValueAnimator laggy
Listview doesn't appear at Fragment after second compile
App crashing android security exception(missing internet permission?)
Hiding the navigation bar in Android, strange issue
Sorting rss feeds by publish date in android
How to Check is Android Download manger enabled? [duplicate]

Categories

HOME
fpga
3d
themes
jelastic
saml-2.0
jwplayer
solver
newrelic
parameters
spring-session
crystal-reports-2013
crystal-lang
mql5
g++
vimdiff
openpyxl
google-form
atlassian-stash
red5
soci
simpleitk
drive
ag
imagemap
react-toolbox
exploit
beautifier
nstimer
oculus
angular-translate
winpe
magento-1.8
kudu
playstation-portable
fossil
sql-delete
baidu-map
engine.io
openproject
git-rewrite-history
release
bc
plr
file-sharing
httrack
nanoc
spring-integration-sftp
mongotemplate
payara-micro
context-switch
wpas
headless
gameplay-kit
cvxpy
mongodb-php
ng-grid
swizzling
angular-ui-typeahead
kiosk
piracy-prevention
user-management
linklabel
tfs-workitem
pypiserver
google-books
ons-api
canalyzer
atoi
zscript
diff3
j-security-check
webmatrix-3
pseudo-class
psr-4
gii
angular-carousel
xml-dsig
websphere-esb
synapse
qscrollarea
jammer
cnf
abstract-data-type
pagedown
device-width
monotouch.dialog
boost-msm
garbage
httponly
apache-commons-dbutils
w3c-geolocation
commerceserver2007
blender-2.49
skype4java
contentpresenter

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