Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

android ListView widget -- an example is needed

 
Monica Marcus
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to build a simple android app using the ListView widget. Can this be done without the so called "adapter"? Because I don't yet understand adapters. In any case , I would like a very simple example to be able to follow. I use eclipse for android. I created a new project called Widgets_2_ListView and I have the activity-main.xml file as follows:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >

<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp" >

</ListView>

</RelativeLayout>

I see a list of 7 items in the corresponding Graphical Layout.

Now what next? Suppose I want to give certain names to the list items and I want 10, not 7 items. What should I do? I would appreciate very much some help.
 
Monica Marcus
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the example at http://www.mkyong.com/android/android-listview-example/ and all I get is an empty screen on my emulator. I don't have any clue as to what went wrong or what is missing.
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't wish to use adapter through code, you need a xml file containing the values for list, and bind this xml to the list. The xml file should be stored under res\values.
 
Monica Marcus
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Swastik, thank you for the suggestion. I did get the ListView using a string_array in the string.xml file. But eventually I want to learn how to use adaptars...
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic