How to finish an activity from an Adapter..?
Solution 1:
type cast it with activity.
((Activity)context).finish();
Solution 2:
Try with the following code:
public YourAdapterName(......,Context context){
...
this.myContext=context;
}
And in your adapter getView()
btn.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
((YourActivityName)myContext).yourDesiredMethod();
}
});
Solution 3:
Try passing your Activity as an activity
parameter, then you'll be able to call finish()
on it. Hope this helps.
Solution 4:
Code for this is ((Activity)context).finish();
and complete code is
holder.cardUsers.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent1=new Intent(mcontext,AstroChatPanel.class);
intent1.putExtra("mobile",userslist.get(position).getMobile());
intent1.putExtra("name",userslist.get(position).getName());
intent1.putExtra("type","admin");
mcontext.startActivity(intent1);
((Activity)mcontext).finish();
}
});