【问题标题】:rename android textview重命名android textview
【发布时间】:2012-10-11 04:08:39
【问题描述】:

如何动态重命名android文本视图?我想根据给定的编辑文本答案分配一个名称,该名称必须与已创建的文本视图相关。 例如名称 a 已经在 xml 中分配了一个 res id 例子 最终的 TextView 名称 a = (TextView) this.findViewById(R.id.Texti5);

    editext.setOnKeyListener(new View.OnKeyListener() {
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        if (keyCode==KeyEvent.KEYCODE_ENTER) { 
            if("test1".equalsIgnoreCase(anstext.getText().toString())) {
                 // Here i want to give textview1 the 'name a'
                }}
            else
            if("test2".equalsIgnoreCase(editext.getText().toString())) {
                // Here i want to give textview1 the 'name b'
            }

        if("test5".equalsIgnoreCase(editext.getText().toString())) {
            // Here i want to give textview1 the 'name c'
        }

        if("test7".equalsIgnoreCase(editext.getText().toString())) {
            // Here i want to give textview1 the 'name d'
        }
        if (editext.getText().toString() != null){
          testwrong.seText("wrong");               }
        }
      // here i want to see what name is given and give the name to textview1 so i can 
         perform click on that textview as it is clickable
      textview1.performClck();
    return true;




    } });

【问题讨论】:

    标签: android textview android-edittext rename


    【解决方案1】:

    也许可以实现类似目标的方法是根据您的 if 语句为 textview 赋予标签。

    textview1.setTag("a");
    

    然后你可以像这样取回标签:

    if (textview1.getTag() == "a") {
    // do something
    }
    

    这至少比你提议的更传统。

    【讨论】:

      猜你喜欢
      • 2015-04-29
      • 2021-06-18
      • 2018-12-11
      • 2013-09-21
      • 2015-03-23
      • 2016-01-09
      • 1970-01-01
      • 2012-05-08
      • 1970-01-01
      相关资源
      最近更新 更多