Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 2.48 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Display in a toast array list
  2. public static  EditText txt1;
  3. String ag;
  4. public static ArrayList<String> playerList = new ArrayList<String>();
  5. String playerlist[];
  6.  
  7. /** Called when the activity is first created.
  8.  * @param Public */
  9. public void onCreate(Bundle savedInstanceState, Object Public) {
  10.     super.onCreate(savedInstanceState);
  11.     setContentView(R.layout.screen2);
  12.  
  13.     // edittext1 or textview1
  14.     txt1 = (EditText) findViewById(R.id.editText1);
  15.     ag = txt1.getText().toString();
  16.  
  17.     //add more items button
  18.     Button more = (Button) findViewById(R.id.button1);
  19.     more.setOnClickListener(new View.OnClickListener() {
  20.         public void onClick(View view) {
  21.             if (txt1.getText().length() != 0) {
  22.                 String ag = "Current Added Players:," + txt1.getText().toString() + txt1.getText().toString();
  23.                 playerList.add(ag);
  24.                 Toast.makeText(getBaseContext(), ag, Toast.LENGTH_SHORT).show();
  25.  
  26.                 Intent myIntent = new Intent(view.getContext(), Screen2.class);
  27.                 myIntent.putExtra("Stringarray", playerList);
  28.                 //startActivityForResult(myIntent, 0);
  29.             }
  30.         }
  31.     });
  32. }
  33.        
  34. String[] playerArray = (String[]) playerList.toArray();
  35. String playerToast = playerArray[0];
  36. for(int i=1; i<playerArray.length(); i++){
  37.     playerToast += " ";
  38.     playerToast += playerArray[i];
  39. }
  40. Toast.makeText(getBaseContext(), playerToast, Toast.LENGTH_SHORT).show();
  41.        
  42. String ag = "Current Added Players:," +txt1.getText().toString() + txt1.getText().toString() ;
  43.        
  44. "Current Added Players:," +txt1.getText().toString() + txt1.getText().toString()
  45.        
  46. for(int i, i < playerList.length, i++) {
  47.       Toast.makeText(this, playerList[i], Toast.LENGTH_SHORT)
  48.            .show();
  49.  }
  50.        
  51. ArrayList<String> a = new ArrayList<String>();
  52. a.add("Hello");
  53. a.add("World"); //similarly any other add statements
  54. Toast.makeText(getBaseContext(), a+"", Toast.LENGTH_SHORT).show();
  55.        
  56. [Hello,World,...other elements what is stored in the arraylist]
  57.        
  58. //add more items button
  59.     Button more = (Button) findViewById(R.id.button1);
  60.     more.setOnClickListener(new View.OnClickListener() {
  61.         @Override
  62.         public void onClick(View view){
  63.             player = txt1.getText().toString();
  64.             if (txt1.getText().toString().length() !=0){
  65.                 playerList.add(player);
  66.                 txt1.setText("");
  67.             }
  68.             Toast.makeText(getBaseContext(), playerList + " ",  Toast.LENGTH_LONG).show();
  69.  
  70.         }
  71.  
  72.     });