populating a ListView with text

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

populating a ListView with text

Postby rdormer » Tue Dec 16, 2008 12:30 am

Hello all,

Forgive what may be a simple question here, but:

how do I programatically populate a ListView with text? I have an array of strings i'd like to appear in a ListView, as if I'd used the entries key in the ListView XML, but i would like to do this from the code.

How do I do this? I've read the file browser tutorials but I'm still drawing a blank.
rdormer
Freshman
Freshman
 
Posts: 8
Joined: Tue Dec 16, 2008 12:26 am

Top

Re: populating a ListView with text

Postby Rahul » Tue Dec 16, 2008 10:24 am

You can have a look at this code

Click Here


rdormer wrote:Hello all,

Forgive what may be a simple question here, but:

how do I programatically populate a ListView with text? I have an array of strings i'd like to appear in a ListView, as if I'd used the entries key in the ListView XML, but i would like to do this from the code.

How do I do this? I've read the file browser tutorials but I'm still drawing a blank.
Rahul
Experienced Developer
Experienced Developer
 
Posts: 89
Joined: Wed Oct 01, 2008 11:16 am

Postby rdormer » Tue Dec 16, 2008 3:25 pm

Is there a way to do the same thing if you're not using a ListActivity?
rdormer
Freshman
Freshman
 
Posts: 8
Joined: Tue Dec 16, 2008 12:26 am

Postby MrSnowflake » Tue Dec 16, 2008 3:33 pm

A ListActivity is not a very special activity, it jsut makes some list related operations easier. So you can just change your activity from extending Activity to ListActivity. And yes this also can be done using a normal Activity, look for the apropriate methods in the ListView and Adapter docs.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby rdormer » Tue Dec 16, 2008 3:39 pm

I'm extending someone else's code, so unfortunately I cannot change the base class that they have chosen for their activities :( That said, ListView and Adapter are exactly where my confusion is - I don't know how they relate to eachother, and it seems like things are mostly done by subclassing Adapter. Do I have to subclass Adapter just to make a class to display strings, or is there some standard way of doing this?
rdormer
Freshman
Freshman
 
Posts: 8
Joined: Tue Dec 16, 2008 12:26 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests