Jobin
Jobin

Reputation: 91

Android fragment to Activity method calling

I have three files such as

  1. activity class
  2. db handler class
  3. fragment class

From my resource file, on a button click I am calling a method (add). The method is defined in the DB Class. and I am trying to call it from the fragment class related with the res file. But when I do I am getting an error:

Could not find a method add(View) in the activity class MainActivity for onClick handler on view class android.widget.Button with id 'btStartCall'

I think I need to initialize the method in activity class to use it. But I am not sure how to do it. Can anyone help me with a simple example?

Upvotes: 0

Views: 179

Answers (1)

M D
M D

Reputation: 47807

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'"

You should add add(View) method in your MainActivity just like:

  public void add(View v){
  //do your job
  }

Upvotes: 1

Related Questions