how to close activity from event
I have the following code
public class DevCl开发者_开发问答ick implements OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) { ... }
This is called from ListView from the activity. I want in that event that the caller activity will close. how can I get the activity from this event??
Thanks
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) { finish(); }
just only call finish function for closing activity.
Implement a custom constructor for your class an pass the activity as a parameter.
public class DevClick implements OnItemClickListener {
private Activity mActivity;
public DevClick(Activity activity){
mAcitvity = activity;
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
mActivity.finish();
}
}
you can create a constructor of your class DevClick with a argument of you caller activity then you can finish this activity from the event.
public DevClick (Context ctx){
this.context = ctx;
}
Just call finish() whenever you want.
精彩评论