从另一个活动的片段中定义的活动中调用方法 [英] Calling a method from a activity which is defined in fragment of another activity
问题描述
假设我有一个名为SearchActivity.java的actvity,它有一个方法dosearch()。
有一个名为fragment.java的片段类,它从MainActivity.java类调用
我可以在fragment.java中调用dosearch()方法吗?
如果可能的话怎么打电话?
我想点击fragment.java类中的按钮调用这个dosearch()方法。
我尝试了什么:
i尝试从片段类中的活动调用方法另一个活动..但是没有用?
Suppose i have a actvity named "SearchActivity.java" which has a method dosearch().
there is fragment class named "fragment.java" and it is called from "MainActivity.java" class
can i call dosearch() method in fragment.java?
if possible how to call?
and i want to call this dosearch() method on click of a button in fragment.java class.
What I have tried:
i tried calling a method from a activity in fragment class of another activity..but did not work?
推荐答案
为了调用dosearch()
方法在片段
类中,你需要制作dosearch()
方法static
,或者你需要一个SearchActivity
对象。
In order to call thedosearch()
method from within thefragment
class, you'd either need to make thedosearch()
methodstatic
, or you would need aSearchActivity
object.
这篇关于从另一个活动的片段中定义的活动中调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!