How to add functions to buttons in an Android layout?

Joe_Vj _95

How to reference a function in a java Activity file to a xml layout file in AIDE?

Matthew Pape

I have never used AIDE myself, but I assume you are still able to edit the xml and java code? Write your function in java (suppose it is called doSomething), then call it when the button is clicked on. You can accomplish this two different ways.

1) Hook it up via xml

<Button 
    android:id="@+id/my_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_text"
    android:onClick="doSomething"/>

2) Hook it up via java

Button button = (Button) rootView.findViewById(R.id.my_button);
button.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        doSomething();
    }
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to add buttons on an overlay layout with an image

From Dev

Add Buttons to Relative Layout Dynamically or Extended Linear Layout android

From Dev

Add Buttons to Relative Layout Dynamically or Extended Linear Layout android

From Dev

How do I dynamically add buttons using Java in a given XML layout file in android studio?

From Dev

Android - How to add several buttons with different layout_margins in a LinearLayout programmatically?

From Dev

how to add buttons dynamically in android?

From Dev

android how to set buttons in layout for all resolution

From Dev

Android - how to access buttons inside include layout

From Dev

Issue with android buttons layout

From Dev

How to add buttons to search view in android toolbar?

From Dev

How to add buttons into each cell of Gridview in Android?

From Dev

How to add Buttons to a push notification in Android

From Dev

How to add buttons to grid view?- Android

From Dev

How to add buttons inside android notifications

From Dev

How to set a linear layout of buttons at the top of an image (layouts in android)?

From Dev

How to align buttons in android layout to make a tabbar in a mobile website?

From Dev

Android: How to inflate different layout from different buttons?

From Dev

Make Android layout buttons into squares

From Dev

Android Design layout with soft buttons or not

From Dev

Make Android layout buttons into squares

From Dev

Android: How to add on/off indicator in xml layout

From Dev

How to add two listviews in a fragment in android layout?

From Dev

How to add this type of layout dynamically (android)

From Dev

How to add a new button in layout of the android programmatically

From Dev

How to add or replace page in android layout view

From Dev

Android How to add ScrollView? ScrollView shits layout

From Dev

Android: How to cover the whole layout by a view programatically while the layout contains buttons already?

From Dev

How to achieve this layout on buttons in Storyboard?

From Dev

In Android how to implement a pop-up screen with buttons. Clicking the buttons calls different functions in the activity

Related Related

  1. 1

    How to add buttons on an overlay layout with an image

  2. 2

    Add Buttons to Relative Layout Dynamically or Extended Linear Layout android

  3. 3

    Add Buttons to Relative Layout Dynamically or Extended Linear Layout android

  4. 4

    How do I dynamically add buttons using Java in a given XML layout file in android studio?

  5. 5

    Android - How to add several buttons with different layout_margins in a LinearLayout programmatically?

  6. 6

    how to add buttons dynamically in android?

  7. 7

    android how to set buttons in layout for all resolution

  8. 8

    Android - how to access buttons inside include layout

  9. 9

    Issue with android buttons layout

  10. 10

    How to add buttons to search view in android toolbar?

  11. 11

    How to add buttons into each cell of Gridview in Android?

  12. 12

    How to add Buttons to a push notification in Android

  13. 13

    How to add buttons to grid view?- Android

  14. 14

    How to add buttons inside android notifications

  15. 15

    How to set a linear layout of buttons at the top of an image (layouts in android)?

  16. 16

    How to align buttons in android layout to make a tabbar in a mobile website?

  17. 17

    Android: How to inflate different layout from different buttons?

  18. 18

    Make Android layout buttons into squares

  19. 19

    Android Design layout with soft buttons or not

  20. 20

    Make Android layout buttons into squares

  21. 21

    Android: How to add on/off indicator in xml layout

  22. 22

    How to add two listviews in a fragment in android layout?

  23. 23

    How to add this type of layout dynamically (android)

  24. 24

    How to add a new button in layout of the android programmatically

  25. 25

    How to add or replace page in android layout view

  26. 26

    Android How to add ScrollView? ScrollView shits layout

  27. 27

    Android: How to cover the whole layout by a view programatically while the layout contains buttons already?

  28. 28

    How to achieve this layout on buttons in Storyboard?

  29. 29

    In Android how to implement a pop-up screen with buttons. Clicking the buttons calls different functions in the activity

HotTag

Archive