Search code examples
javaadditionstore

How to store EditText input into existing ArrayList


I am trying to take the input from an EditText field and store it into an existing ArrayList. I have errors in my code but I cannot find them. Any help would be greatly appreciated.

sButton = (Button) this.findViewById(R.id.button2);
    eText = (EditText) this.findViewById(R.id.editText1);

    sButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {

             Log.v("EditText", eText.getText().toString());
             eText.setText(getText(0));

Solution

  • To get it in an arraylist you do this.. But not sure if that's what you're stuck at atm.

    Top of your class :

    ArrayList<string> list = new ArrayList<string>();
    

    and in your method

         @Override
         public void onClick(View view) {
            list.add(eText.getText().toString());
         }