- Display in a toast array list
- public static EditText txt1;
- String ag;
- public static ArrayList<String> playerList = new ArrayList<String>();
- String playerlist[];
- /** Called when the activity is first created.
- * @param Public */
- public void onCreate(Bundle savedInstanceState, Object Public) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.screen2);
- // edittext1 or textview1
- txt1 = (EditText) findViewById(R.id.editText1);
- 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) {
- String ag = "Current Added Players:," + txt1.getText().toString() + txt1.getText().toString();
- playerList.add(ag);
- Toast.makeText(getBaseContext(), ag, Toast.LENGTH_SHORT).show();
- Intent myIntent = new Intent(view.getContext(), Screen2.class);
- myIntent.putExtra("Stringarray", playerList);
- //startActivityForResult(myIntent, 0);
- }
- }
- });
- }
- String[] playerArray = (String[]) playerList.toArray();
- String playerToast = playerArray[0];
- for(int i=1; i<playerArray.length(); i++){
- playerToast += " ";
- playerToast += playerArray[i];
- }
- Toast.makeText(getBaseContext(), playerToast, Toast.LENGTH_SHORT).show();
- String ag = "Current Added Players:," +txt1.getText().toString() + txt1.getText().toString() ;
- "Current Added Players:," +txt1.getText().toString() + txt1.getText().toString()
- for(int i, i < playerList.length, i++) {
- Toast.makeText(this, playerList[i], Toast.LENGTH_SHORT)
- .show();
- }
- ArrayList<String> a = new ArrayList<String>();
- a.add("Hello");
- a.add("World"); //similarly any other add statements
- Toast.makeText(getBaseContext(), a+"", Toast.LENGTH_SHORT).show();
- [Hello,World,...other elements what is stored in the arraylist]
- //add more items button
- Button more = (Button) findViewById(R.id.button1);
- more.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view){
- player = txt1.getText().toString();
- if (txt1.getText().toString().length() !=0){
- playerList.add(player);
- txt1.setText("");
- }
- Toast.makeText(getBaseContext(), playerList + " ", Toast.LENGTH_LONG).show();
- }
- });