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
|
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);
}
}
});
}}
|
|
|