如何将文本添加到editext [英] How to add text to editext

查看:73
本文介绍了如何将文本添加到editext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在填充edittext时遇到了问题.使用以下代码,我可以将文本设置得很好,但是我想做的是添加到edittext中.例如,以下代码在我的edittext中显示一个"1",但是如果再次按下它,它将用"1"替换"1",依此类推.我需要的是,如果我按四次,它会显示"1111".

I've got a problem with populating an edittext. Using the following code i can set the text just fine, however what i am trying to do is add to the edittext. For example the following code displays a "1" in my edittext but if I press it again it just replaces the "1" with "1" and so on. What i need is it to display "1111" if I press it four times.

这是我的代码:

@Override
    public void onClick(View v) {
        switch (v.getId()) {
                    case R.id.button1:

                        Button txtnum = (Button) findViewById(R.id.button1);

                        Bundle bundle = new Bundle();
                        bundle.putString("number1", txtnum.getText().toString());
                        String title = bundle.getString("number1");
                        ((EditText) findViewById(R.id.editText1)).setText(title);



                        break;

希望有道理. (我是菜鸟) 如果有人可以帮助我,我将非常感激. 谢谢史蒂夫

Hope this makes sence. (I'm a noob) If anyone can help me with this I'd really appreciate it. thanks Steve

推荐答案

尝试此代码

String title = bundle.getString("number1");
EditText editText = (EditText) findViewById(R.id.editText1);
editText.append(title);

如果要设置唯一的新值,请使用

if you want to set the only new value use this

editText.setText(title);

这篇关于如何将文本添加到editext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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