Go Back   Android Forums > Android Discussion > Android Applications
Android Applications All the information you could ever want about Android Applications. Learn about apps and get help with them... all here! New apps can be found and announced in the Applications Announcements forum linked below.

test: Reply
 
LinkBack Thread Tools
Old February 27th, 2012, 10:03 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Feb 2012
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Post EditText input into array help plz!

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:
import java.util.ArrayList;

import android.widget.EditText;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.widget.Toast;
public class Screen2 extends Activity {
    private EditText txt1;
    String ag;
        
    ArrayList<String> playerList = new ArrayList<String>();
    String playerlist[];

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.screen2);

        // edittext1 or textview1
        txt1 = (EditText) findViewById(R.id.editText1);
        ag = txt1.getText().toString();
Done Button:
Code:
        // done button
        // -----done button-------
        Button done = (Button) findViewById(R.id.button2);
        done.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                        
            if(txt1.getText().length() != 0){
                String ag = "Players:," +txt1.getText().toString();
                 //playerList.add(ag);
                Toast.makeText(getBaseContext(), ag,
                Toast.LENGTH_SHORT).show();
        
            Intent myIntent = new Intent(view.getContext(),
                Screen3.class);
                    startActivityForResult(myIntent, 0);
                                
            }else if (txt1.getText().length() == 0){
                String ag = "Error!! Enter Player Name";
                    Toast.makeText(getBaseContext(), ag,
            Toast.LENGTH_SHORT).show();
            }}

            });
Add more items button, need help here

Code:
 
        
        //add more items button
        Button more = (Button) findViewById(R.id.button1);
        more.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view){
                if(txt1.getText().length() != 0){
                    String ag = "Players:," +txt1.getText().toString();
                     playerList.add(ag);
                    Toast.makeText(getBaseContext(), ag,
                    Toast.LENGTH_SHORT).show();
                    
                Intent myIntent = new Intent(view.getContext(),
                        Screen2.class);
                            startActivityForResult(myIntent, 0);
            }
            }

        });
}}

Advertisements
notageekgirl is offline  
Reply With Quote
sponsored links
Reply
Tags
android, button, edittext, input


Go Back   Android Forums > Android Discussion > Android Applications
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 02:40 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.