0

I have a list view with couple of items and i set this function get call when a row in the list view is clicked.

I want to open new activity and send him an object from an array of objects. I have a problem with this line :

Intent i = new Intent(this, Item_Activity.class);

because the this is now no the activity.

this is the code:

lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
         public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
             Intent i = new Intent(this, Item_Activity.class);
             Item item = m_items.get(position);
             i.putExtra("object", item);
             startActivity(i);
         }

    });
YosiFZ
  • 7,792
  • 21
  • 114
  • 221

4 Answers4

1

Problem:

You are passing the wrong context in

Intent i = new Intent(this, Item_Activity.class);

Solution:

Use : YourActivityName.this instead if using simply this

eg. Intent i = new Intent(CurrentActivityName.this, Item_Activity.class);

Kartik Domadiya
  • 29,868
  • 19
  • 93
  • 104
1

Add ActivityName.this instead of this only,

Intent i = new Intent(ActivityName.this, Item_Activity.class);

Rupali
  • 774
  • 7
  • 15
0

is your Item is parcelable, if not make this object parcelable by following link: http://prasanta-paul.blogspot.in/2010/06/android-parcelable-example.html

jeet
  • 29,001
  • 6
  • 52
  • 53
0

Your object has to be either serializable or parcelable and I don't think you can pass an array into an intent read this - How to pass an object from one activity to another on Android

more to that

passing an array in intent android

Community
  • 1
  • 1
Sergey Benner
  • 4,421
  • 2
  • 22
  • 29