1

I'm writing an android app that has 2 activities: ListActivities, EditActivity.

The first shows a list of items with title and description.

the second shows full details after an item form the list was selected.

I also have a custom ListAdapter class that renders the list items for the first activity.

I want to send an intent from activity (1) to (2) sending the selected item's title as an extra data in the intent.

How can I reach this title? as on click I get the basic view class:

protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        Intent i = new Intent(this, TodoDetailActivity.class);


        i.putExtra(.., title);


        // Activity returns an result if called with startActivityForResult
        startActivityForResult(i, ACTIVITY_EDIT);
    }
Elad Benda
  • 35,076
  • 87
  • 265
  • 471

1 Answers1

1

It will be something like below. I assume you have your own class for your items in the list, so replace YourItem with your item's class.

protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Intent i = new Intent(this, TodoDetailActivity.class);

    YourItem item = (YourItem) l.getItemAtPosition(position);

    i.putExtra(.., item.title);


    // Activity returns an result if called with startActivityForResult
    startActivityForResult(i, ACTIVITY_EDIT);
}
Szymon
  • 42,577
  • 16
  • 96
  • 114
  • but again `l.getItemAtPosition(position);` needs to use the List data stracture which is (again) in my ListAdapter – Elad Benda Oct 05 '13 at 22:24
  • Custom `ListAdapter` and `ArrayAdapter` shouldn't need anything special. How do you pass your list to the adapter. As long as it goes through the proper `super` constructor, the adapter will handle it. – Szymon Oct 05 '13 at 22:29
  • Check this question also: http://stackoverflow.com/questions/8166497/custom-adapter-for-list-view – Szymon Oct 05 '13 at 22:29