android如何在适配器内调用startActivityForResult

use*_*935 8 java android android-adapter android-activity android-adapterview

我有一个适配器类:

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

我想在startActivityForResult点击按钮时打电话,我知道我可以这样打电话startActivity:

context.startActivity() 
Run Code Online (Sandbox Code Playgroud)

但我正在寻找有结果的活动,请问怎么样?

Wil*_*aan 21

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);
    }
});
Run Code Online (Sandbox Code Playgroud)