Android的切换按钮国家规定texview文本 [英] android toggle button state set texview text

查看:251
本文介绍了Android的切换按钮国家规定texview文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有设定当切换按钮到开启位置的提示设置为我的TextView之一


  

公斤



文本视图的初始提示是


  

ST


如果切换是在关闭位置它应该显示

当我第一次启动应用程序TextView的dispalys


  

ST


(起初是确定的切换处于关闭位置)现在,当我preSS它原来的位置上,并显示切换


  

公斤


在TextView中(这也是好的。)

现在问题来了。如果我再次切换点击(关闭位置)的TextView保持原样


  

公斤


没有人知道如何我可以将其设置为在在关闭状态下的ST和始终显示公斤状态。

提前很多感谢

  addListenerOnButton();      }      公共无效addListenerOnButton(){        unitToggle =(按钮)findViewById(R.id.unitToggle);
       最终的TextView TW1 =(的TextView)findViewById(R.id.tw1);
        unitToggle.setOnClickListener(新OnClickListener(){            公共无效的onClick(视图v){               StringBuffer的结果=新的StringBuffer();
               tw1.setHint(公斤);


解决方案

  unitToggle.setOnClickListener(新OnClickListener(){        公共无效的onClick(视图v){           StringBuffer的结果=新的StringBuffer();
           如果(tw1.getHint()。的toString()。等于(千克))
                tw1.setHint(ST);
           其他
                tw1.setHint(公斤);

i have a toggle button which when set to the on position sets the hint to one of my textview to

"kg"

. the initial hint of the text view is

"st"

which should be shown if the toggle is in the off position.

when i first start the app the textview dispalys

"st"

(which at first is ok as the toggle is in the off position) now when i press the toggle it turns to the on position and displays

"kg"

in the textView (this is also ok.)

now comes the problem. if i click on the toggle again (off position) the textView stays as

"kg"

does anyone know how i could set it to always display "st in the off state and "kg" in the on state.

many thanks in advance

addListenerOnButton();

      }

      public void addListenerOnButton() {

        unitToggle = (Button) findViewById(R.id.unitToggle);
       final TextView tw1 = (TextView)findViewById(R.id.tw1);


        unitToggle.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

               StringBuffer result = new StringBuffer();
               tw1.setHint("kg");

解决方案

 unitToggle.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

           StringBuffer result = new StringBuffer();
           if(tw1.getHint().toString().equals("kg"))
                tw1.setHint("st");             
           else
                tw1.setHint("kg");

这篇关于Android的切换按钮国家规定texview文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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