Question About an Android Dev Code

This topic contains 2 replies, has 1 voice, and was last updated by  Abhey 3 years, 1 month ago.

  • Author
  • #9758

    I am recently studying Android development and on one of the books i’m reading, it has a code that looks like this:

    A piece of code from the XML file looks like this

    And on the java source file, the method looks like this

    The method looks like it is being passed/accepting an object of type View with the name view. But when the button is clicked, i don’t see anything passed by the XML command to the java method. Can someone explain to me what the (View view) actually does? Sorry if I sound noob lol but I don’t want to move past the chapter I’m in without understanding the whole thing

  • #9759


    Here buttonClickedis internally mapped with the Java code.
    When you click on button your buttonClicked(View view) method will be called.

    You can register listener to your button like this as well in your code:

    Then your class can implement onClickListener interface.
    You need to overrid onClick(View v) for this.

    Now when you click on button your overided
    onClick(View v) method will be called.

  • #9760


    The View parameter on buttonClicked event passes the view (a Button is a View) that was clicked.

    I suggest that instead of reading a book, which only give us a general view about Android programming, just read the documentation which give us deeper understanding about the features presented in Android API.

You must be logged in to reply to this topic.