单击按钮时,可以在java代码中将按钮文本更改为“ok” [英] Button text should be changed to “ok” in the java code programmably, when the button is clicked

查看:122
本文介绍了单击按钮时,可以在java代码中将按钮文本更改为“ok”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为活动提供了以下布局XML。单击按钮时,可以在Java代码中将按钮文本更改为ok。请写下代码来完成它。只需写下与要求直接相关的陈述。



我尝试过:



<?xml version =1.0encoding =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>

解决方案

按钮mybtn =(按钮)findViewById(R .id.my_button); 
mybtn.setText( OK);


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>

解决方案

Button mybtn = (Button) findViewById(R.id.my_button);
mybtn.setText("OK");


这篇关于单击按钮时,可以在java代码中将按钮文本更改为“ok”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆