EZ 1. How to display text view based on list item selection?

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

EZ 1. How to display text view based on list item selection?

Postby deenybird » Sun Jan 25, 2009 10:37 pm

I would like to have the user presented with a 'list view' of several options. Clicking on one of the items opens up a text view on a new screen with relevant text.

How do I pass the ID number of the list item so i can pull up a specific text view?

thanks a bunch.
deenybird
Developer
Developer
 
Posts: 25
Joined: Sat Nov 29, 2008 12:35 am

Top

Postby MrSnowflake » Sun Jan 25, 2009 11:04 pm

Intent.putExtra(someKey, ID); and then you can retreive it in the called Activity.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby deenybird » Tue Jan 27, 2009 12:47 am

thanks for your prompt reply mr snowflake.

I am having trouble figuring out which listview method i need to use to get the variable which represents the selected item in the listview.

I believe its setonitemselectedlistener, but in the parenthesis of the method that it creates are variables like View arg1, int arg2 etc... Does it work like a spinner where the first item has the ID of 0, the second item ID is 1, or is there an if statement for the string? Also, should I be using a listadapter versus an arrayadapter for this?

listview1.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {

Intent.putExtra(someKey, ID)

}
}

I would assume your previous answer would go in the selecteditem method as i listed above, but which one of those (somekey or ID) represents the item i'm pulling from that method? So once i have the key do i have to use an intent to grab it in the other class, or can i call it by itself without using an intent?
deenybird
Developer
Developer
 
Posts: 25
Joined: Sat Nov 29, 2008 12:35 am

Postby MrSnowflake » Tue Jan 27, 2009 11:44 am

arg2 or arg3 are either the id of the item in the list, or the id of the item in the adapter, or in reverse, so you have to test this out which is the one you need.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby deenybird » Wed Jan 28, 2009 12:06 am

So the onItemSelectedListener is correct? Do I use an arrayadapter or a listadapter?

Once I've used the intent to put the variable. Do I need an intent to call it in the other class?
deenybird
Developer
Developer
 
Posts: 25
Joined: Sat Nov 29, 2008 12:35 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 12 guests