Start Activity From Adapter Don't Work With Swipelistview Library
I'm using SwipeListView library and I'm getting error when trying to start an activity in my adapter. public class ProductAdapter extends ArrayAdapter { private Con
Solution 1:
context
is a field of ProductAdapter
in your case and you don't initialize it with any value, so it's null
. Use getContext()
instead or initialize context
field with this.context = context
.
Solution 2:
You are receiving the Context
in the constructor, so you can store into the variable context:
private Context context;
publicProductAdapter(Context context, int textViewResourceId, List<Product> objects) {
super(context, textViewResourceId, objects);
this.context = context; //*** Here!
}
And use it into your Adapter
class, for example:
......
viewHolder.bAction1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, MainActivity.class);
context.startActivity(intent);
}
});
......
Post a Comment for "Start Activity From Adapter Don't Work With Swipelistview Library"