Gaurav Agarwal
Gaurav Agarwal

Reputation: 19102

How to fire an Intent from ListAdapter?

Any help will be highly appreciated. I am using a ImageButton in each row of a ListView. When user presses the Button, I need to fire another activity. I have written the code

viewHolder.editWordButton.setOnClickListener(new OnClickListener()  {
@Override
public void onClick(View v) {
   Intent i = new Intent(view.getContext(), EditTextClass.class);
   startActivity(i);
}
});

But it does not identify function startActivity(i)?

Upvotes: 0

Views: 686

Answers (2)

Orest
Orest

Reputation: 1897

because there is no such function in this class OnClickListener. Try calling it from context, or if it will not work from applicationContext

Upvotes: 1

jtt
jtt

Reputation: 13541

You do realize that startActivity(..) is not a method of an OnClickListener? Where does startActivity(...) come from? Why it comes from Context. So knowing this, how can you start the activity, what do you need? CONTEXT.

Upvotes: 2

Related Questions