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
EDIT : Here is the edited code:
private EditText txt1;
public static 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);
final String ag = txt1.getText().toString();
//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){
playerList.add(ag);
DisplayToast("Current Players" + playerList);
Intent myIntent = new Intent(view.getContext(),
Screen2.class);
myIntent.putExtra("playerList",playerList);
startActivity(myIntent);
}
}});
}
//display message
private <Strg> String DisplayToast(String ag) {
Toast.makeText(getBaseContext(), ag, Toast.LENGTH_LONG)
.show();
return ag;
}}
While onClick the done button just pass the string array to next activity and get the values of array in next screen and display it..You can pass the string array as below
In Next activity you can get value as
Edit:
I think it may help you...
Try making your array public static in the activity you are currently in.Then you can directly access that array in next activity.
EDIT :
As per the scenario you declared in your question,Try this code: say this is your Screen1.class:
In your Screen2.class,directly access ArrayList like:
I hope,it's clear now!