简体   繁体   中英

android how to call startActivityForResult inside an adapter

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 ?

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);
    }
});

I just wanted to point a detail which i faced in my case E/ActivityThread(31584): Performing stop of activity that is not resumed: {com.example.test/activities.MainActivity} most probably you are passing getApplicationContext() to the adapter's constructor . In order to avoid this you must provide " CallingActivity.this " to the adapter's constructor as the context object , keep this in mind .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM