[英]Android - startActivityForResult() from a RecyclerViewAdapter inside a Fragment
I want to take a picture by pressing an item inside a RecyclerView
. 我想通过按
RecyclerView
一个项目来拍照。 If I do ((MainActivity)context).startActivityForResult
, onActivityResult
in Activity will be called.. How to call it inside the Fragment
holding the Adapter
? 如果我这样做
((MainActivity)context).startActivityForResult
,则会在Activity中调用onActivityResult
。如何在持有Adapter
的Fragment
内调用它?
I know I can just pass the fragment inside the adapter. 我知道我可以将片段传递到适配器中。 But I'm concerned about the memory usage.
但我担心内存使用情况。
If you have a reference to the fragment in the adapter, you can use: 如果您对适配器中的片段有引用,则可以使用:
fragment.startActivityForResult(Intent intent, int requestCode);
Then in the fragment, you need the following: 然后在片段中,您需要以下内容:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.