Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add text to editext

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.

heres my code:

@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

like image 919
steo Avatar asked Sep 06 '11 13:09

steo


People also ask

Can you set text in EditText?

Set the Text of Android EditText In android, we can set the text of EditText control either while declaring it in Layout file or by using setText() method in Activity file. Following is the example to set the text of TextView control while declaring it in XML Layout file.


1 Answers

try this code

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);
like image 177
Balaji.K Avatar answered Oct 31 '22 18:10

Balaji.K