如何隐藏文本字段的情况下,并显示它时,点击按钮 [英] how to hide the context of a text field and show it when click button

查看:131
本文介绍了如何隐藏文本字段的情况下,并显示它时,点击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何隐藏文本字段的情况下,并显示当我点击 按钮 我不想隐藏已归档的只是我写它里面的背景下全文 并显示OT当我点击一个按钮 * 的 这是一个小code *

 包com.example.nonachan;

    进口android.R.string;
    进口android.os.Bundle;
    进口android.app.Activity;
    进口android.view.Menu;
    进口android.view.View;
    进口android.widget.Button;
    进口android.widget.EditText;
    进口android.widget.ImageButton;
    进口android.widget.TextView;

    公共类MainActivity延伸活动{

    所以char a;
    焦B:
    焦炭℃;
    INT I = 0;
    焦炭BUF;
        @覆盖
        公共无效的onCreate(包savedInstanceState){
            super.onCreate(savedInstanceState);
            的setContentView(R.layout.activity_main);

            最后的EditText T =(EditText上)findViewById(R.id.t1);
                 的ImageButton N =(的ImageButton)findViewById(R.id.b1);
                n.setOnClickListener(新View.OnClickListener(){
                    @覆盖
                    公共无效的onClick(查看为arg0){
                        // TODO自动生成方法存根

                        A ='A';
                       t.se​​tText(t.getText()的toString()+ A。);
                    // t.setVisibility(View.INVISIBLE);

                    }

                });

                的ImageButton A =(的ImageButton)findViewById(R.id.b2);
                a.setOnClickListener(新View.OnClickListener(){
                    @覆盖
                    公共无效的onClick(查看为arg0){
                        // TODO自动生成方法存根

                         B =B;
                         t.se​​tText(t.getText()的toString()+ B);

                        // t.setVisibility(View.INVISIBLE);
                         我++;

                    }
                });

                的ImageButton M =(的ImageButton)findViewById(R.id.b4);
                m.setOnClickListener(新View.OnClickListener(){
                    @覆盖
                    公共无效的onClick(查看为arg0){
                        // TODO自动生成方法存根

                         C ='C';
                         t.se​​tText(t.getText()的toString()+ C);

                         //t.setVisibility(View.INVISIBLE);
                         我++;

                    }
                });

                按钮L =(按钮)findViewById(R.id.b3);
                l.setOnClickListener(新View.OnClickListener(){

                    @覆盖
                    公共无效的onClick(查看为arg0){
                        // TODO自动生成方法存根
                    // t.setVisibility(View.VISIBLE);
                    }

                });

        }

        @覆盖
        公共布尔onCreateOptionsMenu(功能菜单){
            //充气菜单;这增加了项目操作栏,如果它是present。
            。getMenuInflater()膨胀(R.menu.main,菜单);
            返回true;
        }

    }
 

解决方案

假设你已经在你的问题拼写错误的内容作为背景(看起来很有可能)

而不是试图隐藏的EditText 的内容,只是将其保存到一个变量,并设置了的EditText 空。然后在您的按钮,点击刚才设置的文本回的内容在本地变量

例如:

 字符串hiddenText = NULL;

文字的EditText =(EditText上)findViewById(R.id.t1);

的ImageButton隐藏=(的ImageButton)findViewById(R.id.b1);
btn.setOnClickListener(新View.OnClickListener(){
    @覆盖
    公共无效的onClick(查看为arg0){
        //保存和隐藏
        hiddenText = text.getText();
        text.setText();
    }
});

的ImageButton取消隐藏=(的ImageButton)findViewById(R.id.b2);
btn.setOnClickListener(新View.OnClickListener(){
    @覆盖
    公共无效的onClick(查看为arg0){
        //取消隐藏文本和清除hiddenText
        如果(hiddenText!= NULL){
            text.setText(hiddenText);
            hiddenText = NULL;
        }
    }
});
 

how do i hide the context of the text field and show it when i click the button i do not want to hide the whole text filed just the context i wrote inside it and show ot when i click a button * this is a small code*

  package com.example.nonachan;

    import android.R.string;
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.ImageButton;
    import android.widget.TextView;

    public class MainActivity extends Activity {

    char a;
    char b;
    char c; 
    int i = 0; 
    char buf;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            final EditText t =(EditText)findViewById(R.id.t1);  
                 ImageButton n = (ImageButton)findViewById(R.id.b1);            
                n.setOnClickListener(new View.OnClickListener() {       
                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub

                        a = 'a';
                       t.setText(t.getText().toString() + a);   
                    //   t.setVisibility(View.INVISIBLE);

                    }       

                });

                ImageButton a = (ImageButton)findViewById(R.id.b2);
                a.setOnClickListener(new View.OnClickListener() {     
                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub

                         b = 'b' ;
                         t.setText(t.getText().toString() + b);

                        // t.setVisibility(View.INVISIBLE);
                         i++; 

                    }
                });

                ImageButton m = (ImageButton)findViewById(R.id.b4);
                m.setOnClickListener(new View.OnClickListener() {     
                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub

                         c = 'c' ;
                         t.setText(t.getText().toString() + c);

                         //t.setVisibility(View.INVISIBLE);
                         i++; 

                    }
                });

                Button l = (Button)findViewById(R.id.b3);
                l.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub      
                    //  t.setVisibility(View.VISIBLE);
                    }

                });

        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }

    }

解决方案

Assuming you have misspelled contents as context in your question (looks very likely)

instead of trying to hide the contents of the EditText, just save it to a variable and set the text of the EditText to empty. Then in your button click just set the text back to the contents in your local variable

Eg

String hiddenText = null;

EditText text = (EditText)findViewById(R.id.t1);

ImageButton hide = (ImageButton)findViewById(R.id.b1); 
btn.setOnClickListener(new View.OnClickListener() {       
    @Override
    public void onClick(View arg0) {
        // save and hide
        hiddenText = text.getText();
        text.setText("");
    }       
});

ImageButton unhide = (ImageButton)findViewById(R.id.b2); 
btn.setOnClickListener(new View.OnClickListener() {       
    @Override
    public void onClick(View arg0) {
        // unhide the text and 'clear' hiddenText
        if (hiddenText != null) {
            text.setText(hiddenText);
            hiddenText = null;
        }
    }       
});

这篇关于如何隐藏文本字段的情况下,并显示它时,点击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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