(View) in a parent or ancestor Context for android:onClick attribute defined on view class Button

Posted by Vuyiswamb under Android on 8/30/2017 | Points: 10 | Views : 330 | Status : [Member] [MVP] [Administrator] | Replies : 0
Good Day Everyone

I have an activity class defined like this


[Activity(Label = "Activity_Home", MainLauncher = false, Icon = "@drawable/lenderlogo", Theme = "@style/MyTheme")]
public class Activity_Home : ActionBarActivity //AppCompatActivity
{


and the activity is hosting a Tab that display its content from a fragment. A fragment is defined separately and it has a button that is defined like this

 <Button
android:textSize="10sp"
android:textColor="#FFF"
android:id="@+id/btn_details_save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="btn_details_saveClick"
android:text="Continue" />


as you can see i have a click event that is triggered when the button is clicked. The code to handle the event of the button is defined in the fragment class file like this

//Find Controls to hook 
Button btn_details_save = FindViewById<Button>(Resource.Id.btn_details_save);

// set onclick listener here, by deleting some process
btn_details_save.Click += delegate
{
btn_details_saveClick();
};


and he function itself is defined like this


public void btn_details_saveClick()
{
//Do stuff
}

Now when i run the application, the button is click the button the following error occurs


AndroidRuntime(19059): java.lang.IllegalStateException: Could not find method btn_details_saveClick(View) in a parent or ancestor Context for android:onClick attribute defined on view class Button with id 'btn_details_save'


Please note that this is C# code , which means i am using xamarin ,but the error is Android related not Xamarin.

Thanks

Thank you for posting at Dotnetfunda
[Administrator]



Responses

(No response found.)

Login to post response