Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following layout XML for an activity. The button text should be changed to "ok" in the Java code programmably, when the button is clicked. Please write the code to accomplish that. Just write the statements directly related to the requirement.

What I have tried:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp" >
    <Button
        android:id="@+id/my_button"
        android:layout_width="96dp"
        android:layout_height="wrap_content"
        android:text="@string/done" 
        android:onClick="changeText" 
    />
</RelativeLayout>
Posted
Updated 2-Dec-18 23:08pm

1 solution

Java
Button mybtn = (Button) findViewById(R.id.my_button);
mybtn.setText("OK");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900