简体   繁体   English

条件下按钮用法的文本值

[英]Text value of button usage in condition

I'm trying to make condition where I wanto compare text value of button but it always doesn't match... 我正在尝试让我想要比较按钮的文本值的条件,但它始终不匹配...

<Button android:layout_width="90dp" android:layout_height="40dp" android:gravity="center" android:text="+" android:id="@+id/baton1" android:layout_gravity="left|center_vertical" />

I've tried to print out the value and it shows like "[+]"... 我试图打印出该值,它显示为“ [+]” ...

if (btn.toString().equals("[+]")) {

I assume you did the necessary stuff to reach the button object from the class file. 我假设您做了必要的工作才能从类文件到达按钮对象。

As I know, You need to use getText() method while getting the text property of the objects. 据我所知,您需要在获取对象的text属性时使用getText()方法。

So, you should do something like that; 因此,您应该执行类似的操作;

if (btn.getText().equals("+")) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM