EditText input into array help plz!


  1. notageekgirl

    notageekgirl New Member

    I have an input box (EditText1)

    1. that i want to keep adding values and save them to an Array

    2. then when am done, i can click the done button and it can take me to the next screen and I can display the values or call the values of the array.. this is what i have so far
    1. Done Button Works 2. Add more button and storing to array doesn't quite work....HELP PLZ,
    Thanks


    Code (Text):
    1.  
    2. import java.util.ArrayList;
    3.  
    4. import android.widget.EditText;
    5. import android.app.Activity;
    6. import android.content.Intent;
    7. import android.os.Bundle;
    8. import android.widget.Button;
    9. import android.view.View;
    10. import android.widget.Toast;
    11. public class Screen2 extends Activity {
    12.     private EditText txt1;
    13.     String ag;
    14.        
    15.     ArrayList<String> playerList = new ArrayList<String>();
    16.     String playerlist[];
    17.  
    18.     /** Called when the activity is first created. */
    19.     @Override
    20.     public void onCreate(Bundle savedInstanceState) {
    21.         super.onCreate(savedInstanceState);
    22.         setContentView(R.layout.screen2);
    23.  
    24.         // edittext1 or textview1
    25.         txt1 = (EditText) findViewById(R.id.editText1);
    26.         ag = txt1.getText().toString();
    27.  
    28.  
    Done Button:
    Code (Text):
    1.  
    2.         // done button
    3.         // -----done button-------
    4.         Button done = (Button) findViewById(R.id.button2);
    5.         done.setOnClickListener(new View.OnClickListener() {
    6.             public void onClick(View view) {
    7.                        
    8.             if(txt1.getText().length() != 0){
    9.                 String ag = "Players:," +txt1.getText().toString();
    10.                  //playerList.add(ag);
    11.                 Toast.makeText(getBaseContext(), ag,
    12.                 Toast.LENGTH_SHORT).show();
    13.        
    14.             Intent myIntent = new Intent(view.getContext(),
    15.                 Screen3.class);
    16.                     startActivityForResult(myIntent, 0);
    17.                                
    18.             }else if (txt1.getText().length() == 0){
    19.                 String ag = "Error!! Enter Player Name";
    20.                     Toast.makeText(getBaseContext(), ag,
    21.             Toast.LENGTH_SHORT).show();
    22.             }}
    23.  
    24.             });
    25.  
    Add more items button, need help here

    Code (Text):
    1.  
    2.        
    3.         //add more items button
    4.         Button more = (Button) findViewById(R.id.button1);
    5.         more.setOnClickListener(new View.OnClickListener() {
    6.             public void onClick(View view){
    7.                 if(txt1.getText().length() != 0){
    8.                     String ag = "Players:," +txt1.getText().toString();
    9.                      playerList.add(ag);
    10.                     Toast.makeText(getBaseContext(), ag,
    11.                     Toast.LENGTH_SHORT).show();
    12.                    
    13.                 Intent myIntent = new Intent(view.getContext(),
    14.                         Screen2.class);
    15.                             startActivityForResult(myIntent, 0);
    16.             }
    17.             }
    18.  
    19.         });
    20. }}
    21.  
    22.  

    Advertisement

Share This Page