android how to call startActivityForResult inside an adapter

user2059935 picture user2059935 · Feb 11, 2013 · Viewed 13.3k times · Source

I have an adapter class :

public class AdapterAllAddress extends BaseExpandableListAdapter {
private Context context;
    public AdapterAllAddress(Context context,
            ArrayList<AllAddressesGroup> groups) {
        // TODO Auto-generated constructor stub
        this.context = context;
    }
}

I want to call startActivityForResult when a button click , I know I can call startActivity like this:

context.startActivity() 

but i am looking for activity with results, how please ?

Answer

William Kinaan picture William Kinaan · Feb 11, 2013
yourButton.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub
        Intent intent = new Intent(context, YourNewActivity.class);
        ((Activity) context).startActivityForResult(intent, resultCode);
    }
});