I have a simple app which implement Activity.
I am implementing list-view onItemClickListener like below. However, I need to create an Intent inside this function.
How can I achieve that?
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView <? > arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "Click", Toast.LENGTH_LONG).show();
//need to create intent here to load view
Intent myintent = new Intent(this, MYclass.class);
// but this gives me error
myintent.putExtra("id", "test");
startActivity(myintent);
}
});
you should make some search before posting, I believe you can find number of examples well I think your problem is
Intent myintent = new Intent(this,MYclass.class);
change it to
Intent myintent = new Intent(YourCurrentActivityName.this,MYclass.class);
you are inside an anonymous inner class so this wont work here use like this :
Intent myintent = new Intent(CurrentClassName.this,MYclass.class);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With