Advertisement
Zorge_R

TestArray

Mar 30th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  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.     /* init item id*/
  16.     int idzorge = 0;
  17.     int idramallah = 1;
  18.     int idpakistan = 2;
  19.    
  20.     @Override
  21.     public void onCreate(Bundle savedInstanceState) {
  22.         super.onCreate(savedInstanceState);
  23.         setContentView(R.layout.main);
  24.        
  25.         /* update array from array.xml */
  26.         names = getResources().getStringArray(R.array.array1);
  27.         level = getResources().getStringArray(R.array.array2);
  28.     }
  29.    
  30.     public void onClick1(View view) {
  31.         switch (view.getId()) {
  32.         case R.id.button1: /* if pressed button1 */
  33.             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() */
  34.                      if (i == idzorge   ){tost(i);}
  35.                 else if (i == idramallah){tost(i);}
  36.                 else if (i == idpakistan){tost(i);}
  37.             }break; /* break case */
  38.         case R.id.button2:
  39.             for(int i = 0; i < names.length; i++) {if (i == idzorge){tost(i);}}break;
  40.         case R.id.button3:
  41.             for(int i = 0; i < names.length; i++) {if (i == idpakistan){tost(i);}}break;
  42.         }
  43.     }
  44.    
  45.     public void tost(int arg) {
  46.         Toast toast = Toast.makeText(getApplicationContext(), "user:"+names[arg]+". Level="+level[arg], Toast.LENGTH_SHORT);toast.show();
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement