我有三个文件,例如
- Activity 类别
- 数据库处理程序类
- fragment 类
从我的资源文件中,单击按钮“我正在调用方法(添加)”。该方法在 DB 类中定义。我试图从与 res 文件相关的 fragment 类中调用它。但是当我这样做时,我收到一个错误:
Could not find a method add(View) in the activity class MainActivity for onClick handler on view class android.widget.Button with id 'btStartCall'
我想我需要初始化 Activity 类中的方法才能使用它。但我不知道该怎么做。谁能帮我举一个简单的例子吗?
最佳答案
But when i do I am getting an error telling "Could not find a method add(View) in the activity class MainActivity for onClick handler on view class android.widget.Button with id 'btStartCall'"
您应该在 MainActivity
中添加 add(View)
方法,如下所示:
public void add(View v){
//do your job
}
关于java - Android Fragment到Activity方法调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28979442/