Advertisement
Zorge_R

TestArray 0.0.0.0.1

Mar 30th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.testtingarray.zlab;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Toast;
  7.  
  8. public class TestArrayActivity extends Activity {
  9.     /** Called when the activity is first created. */
  10.    
  11.     /* init array*/
  12.     public String[] names;
  13.     public String[] level;
  14.    
  15.     @Override
  16.     public void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.         setContentView(R.layout.main);
  19.        
  20.         /* update array from array.xml */
  21.         names = getResources().getStringArray(R.array.array1);
  22.         level = getResources().getStringArray(R.array.array2);
  23.     }
  24.    
  25.     public void onClick1(View view) {
  26.         switch (view.getId()) {
  27.         case R.id.button1: /* if pressed button1 */
  28.             for(int i = 0; i < names.length; i++) { /* do toast for all item in array names[] and send item from names[] and level[] to tost() */
  29.                      if (names[i].equals("zorge")){tost(i);}
  30.                 else if (names[i].equals("ramallah")){tost(i);}
  31.                 else if (names[i].equals("pakistan")){tost(i);}
  32.             }break; /* break case */
  33.         case R.id.button2:
  34.             for(int i = 0; i < names.length; i++) {if (names[i].equals("zorge")){tost(i);}}break;
  35.         case R.id.button3:
  36.             for(int i = 0; i < names.length; i++) {if (names[i].equals("pakistan")){tost(i);}}break;
  37.         }
  38.     }
  39.    
  40.     public void tost(int arg) {
  41.         Toast toast = Toast.makeText(getApplicationContext(), "user:"+names[arg]+". Level="+level[arg], Toast.LENGTH_SHORT);toast.show();
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement