Using Parcelable inside setOnItemClickListener
I read through this tutorial to use Parcelable to pass objects between Android activities, but I still get a null pointer when I try to retrieve the object. Any help is appreciated.
Here is the code:
ActivityClassOne ( inside the onCreate() )
final Context context = this;
//recognize when something is clicked in the list
myList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, final View view, int position, long id){
//get the item tapped on
final MyObject mo = (TSEntry) parent.getItemAtPosition(position);
Intent intent = new Intent(context, ActivityClassTwo.class);
intent.putExtra("MYOBJ",mo);
startActivity(intent);
}
});
ActivityClassTwo ( inside the onCreate() )
Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();
if (bundle!=null){
MyObject mo = b.getParcelable("MYOBJ"); //exception here
//other stuff
}
Read more
stackoverflow.comm
No comments:
Post a Comment