[英]How to invoke the method of a fragment that belongs to an activity
With this code I am invoking a method of an activity. 通过此代码,我正在调用活动的方法。
What I require is to invoke a method of a fragment that belongs to an activity. 我需要的是调用属于活动的片段的方法。
if (AppCompatActivity.class.equals(ctx.getClass().getSuperclass())) {
if (callBackName != null) {
Activity activity = (Activity) ctx;
Method method = activity.getClass().getMethod(callBackName, parameters);
method.invoke(activity, response, isError, errorType);
}
}
Make the method (that you are invoking on activity as in your example) call the fragment method .. 使该方法(如您在示例中那样调用活动)调用片段方法..
in Fragment 在片段中
public void iAmFragmentMethodInFragment() {
}
in Activity 活动中
public void iAmActivityMethodInActivity() {
fragment.iAmFragmentMethodInFragment()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.