Input EditText(Type:Number) into array[]

I have an EditText (input type:numberDecimal),that I want to keep adding values with save them to an Array. how can i do this ? for an example:

EditText:"1234"
Array[0]=1;
Array[1]=2;
Array[2]=3;
Array[3]=4;

Thanks...

Answers


Use an ArrayList instead, since you don't know exact number of numbers user going to input.

ArraList<String> list=new ArrayList<String>();

EditText et = (EditText) findViewById(R.id.EditText01);

    et.addTextChangedListener( new TextWatcher()
    {
        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

            try
            {
                char currentChar = arg0.charAt(arg1); // currently typed character
                list.add(currentChar);// Add the character to the list.
            }
            catch(Exception e)
            {
                // error
            }
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                int arg3) {

        }

        @Override
        public void afterTextChanged(Editable arg0) {

        }
    });

TextWatcher is a useful class provided by the Android Developer API. It can be used to watch a input text field and you can instantly update data on other views. It can be useful for counting the number of characters entered in the text field instantly.

EditText et = (EditText) findViewById(R.id.EditText01);

        et.addTextChangedListener( new TextWatcher()
        {
            @Override
            public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

                try
                {
                    char currentChar = arg0.charAt(arg1); // currently typed character
                }
                catch(Exception e)
                {
                    // error
                }
            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                    int arg3) {

            }

            @Override
            public void afterTextChanged(Editable arg0) {

            }
        });

http://www.learn2crack.com/2014/02/android-textwatcher-example.html


Need Your Help

Linker library path in makefile confusion

c++ c linux makefile linker

I've been programming a while but I still don't fully understand how the linker behaves.

Is String.concat slower than Array approach to join strings

javascript

Strings in JavaScript are immutable. Across the web and here on Stack Overflow as well, I came across the Array approach to concatenate strings: