Results 1 to 2 of 2

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

  1. #1

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    829

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

    Good Day Everyone

    I have an activity class defined like this

    Code:
    [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

    Code:
     <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
    Code:
      //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
    Code:
    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 androidnClick 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

  2. #2
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,621

    Re: (View) in a parent or ancestor Context for android:onClick attribute defined on v

    Quote Originally Posted by vuyiswamb View Post
    Good Day Everyone

    I have an activity class defined like this

    Code:
    [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

    Code:
     <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
    Code:
      //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
    Code:
    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 androidnClick 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
    I realize this is a year old, but most likely the findviewbyid isn't finding anything. You should specify the container and look in it like this: tab.findviewbyid( after you've found the tab first.
    My light show youtube page (it's made the news) www.youtube.com/@artnet2twinkly
    Contact me on the socials www.facebook.com/lordorwell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width