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);
}
});
android how to call startActivityForResult inside an adapter
-
09-03-2022 - |
Pregunta
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 ?
Solución
Otros consejos
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 .
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow