views:

192

answers:

1

Ok, so I have this application that takes a adress strings (from values/xml) and parses it your current position) retuning a name, address and distance away. This is then picked up by an arrayadapter and put up on a listview. I cannot for the life of me get the list view to accept an onitemclick to start another activity, where I can launch a different view. I did have it where I was getting the row, name and address to show through to an alert dialog, but in my efforts to get it to launch an activity, I lost that.

So does anyone have any thoughts? I am using the following call to make my list and and arrays. This is stripped down, so assume I have all the imports and proper formatting. I know I am just missing something simple here...

public class Wf extends ListActivity {
private ArrayList<String> DistanceList;
private ArrayAdapter<String> aa;

 @Override
 public void onCreate(Bundle icicle) {
   super.onCreate(icicle);

   // Bind the ListView to an ArrayList of strings.
   DistanceList = new ArrayList<String>();

ListView lv = (ListView)findViewById(R.id.ListView01);

aa = new ArrayAdapter<String>(getApplicationContext(), 
                                 R.layout.listbox_layout,
                                 DistanceList);
lv.setAdapter(aa);

//Call to get distance... here
}

 public void onListItemClick(ListView parent, View v,int position, long id) {
    ListView lv = (ListView)findViewById(R.id.ListView01);
    Toast.makeText(this, "You clicked", Toast.LENGTH_LONG).show();
  }
A: 

From the ListActivity docs:

ListActivity has a default layout that consists of a single, full-screen list in the center of the screen. However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). To do this, your own view MUST contain a ListView object with the id "@android:id/list" (or list if it's in code)

Your ListView does not have the correct ID. Your code is incomplete but I suspect the listener is not being registered with the ListView.

Dan Dyer
I see. Ok, I am actually attempting to use 4 listviews in a single scrollview. I know, sounds crazy, but it being driven by a cosmetic requirement. I wrote a custom listbox_layout for the font control and such. I just wish I could find a good example of this somewhere. Do you know anything? I like to figure this stuff out on my own, but apparently I am getting dumber by the hour.Thanks again,
WJOH
Ok, got it. Now, can I do this on more than one listview in a single parent view? For example a scrollview that has 4 listviews?
WJOH
@WJOH: If you want to use multiple ListViews I don't think you can use ListActivity. You'd have to just use Activity and wire it up yourself.
Dan Dyer