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

Untitled

By: a guest on May 24th, 2012  |  syntax: None  |  size: 3.43 KB  |  hits: 20  |  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. Why does setAlpha() act on all my buttons whilst setImageResource() acts on just one button?
  2. seatButton[i].setAlpha(255);
  3.        
  4. seatButton[i].setImageResource(0x7f020007)
  5.        
  6. @Override
  7. public void onCreate(Bundle savedInstanceState)
  8. {
  9.     super.onCreate(savedInstanceState);
  10.     setContentView(R.layout.main);
  11.  
  12.     table = new Table(); //Creates Table
  13.     seatButton = new ImageButton[10]; //Creates Array of buttons
  14.     seatStats = new TextView[10]; //Creates array for stat panels
  15.  
  16.  
  17.     //Creates longClickListener, used for players to sit in or out.
  18.     longClickListener = new View.OnLongClickListener()
  19.  
  20.  
  21.     {
  22.  
  23.  
  24.         @Override
  25.         public boolean onLongClick(View v)
  26.         {
  27.             for(int i=0; i<10; i++)
  28.             {
  29.                 //Each seat[i] will correspond with each imageButtoni+1
  30.                 if(v.getId() == (getResources().getIdentifier("imageButton" + (i+1), "id", "en.deco.android.livehud")))
  31.                 {
  32.                     //If the seat is empty fill it, place a player in the seat and change the button from translucent to opaque
  33.                     if(table.seats[i].getState().equals("empty"))
  34.                     {
  35.  
  36.                         seatButton[i].setAlpha(255);
  37.                         //seatButton[i].setImageResource(0x7f020000);
  38.                         table.seats[i].sit(new Player());
  39.                         seatStats[i].setVisibility(View.VISIBLE);
  40.                         Toast.makeText(GUI.this, table.seats[i].getState(), Toast.LENGTH_SHORT).show();
  41.                     }
  42.                     //If the seat is full, empty it
  43.                     else
  44.                     {
  45.                         seatButton[i].setAlpha(80);
  46.                         //seatButton[i].setImageResource(0x7f020007);
  47.                         table.seats[i].sitOut();
  48.                         seatStats[i].setVisibility(View.INVISIBLE);
  49.                         Toast.makeText(GUI.this, table.seats[i].getState() + i, Toast.LENGTH_SHORT).show();
  50.                     }
  51.                 }
  52.             }
  53.             return true;
  54.         }
  55.     };
  56.  
  57.  
  58.     //Assigns the buttons and stats panels defined in the layout xml to their appropiate java arrays. Also sets clickListeners to buttons.
  59.     for(int i = 0; i < 10; i++)
  60.     {
  61.         seatButton[i] = (ImageButton) findViewById(getResources().getIdentifier("imageButton" + (i+1), "id", "en.deco.android.livehud"));
  62.         seatStats[i] = (TextView) findViewById(getResources().getIdentifier("textView" + (i+1), "id", "en.deco.android.livehud"));
  63.         seatButton[i].setOnLongClickListener(longClickListener);
  64.         seatButton[i].setAlpha(80);
  65.     }
  66.        
  67. if(table.seats[i].getState() == "empty") { ... }
  68.        
  69. if(table.seats[i].getState().equals("empty")) { ... }
  70.        
  71. //Initializes AlphaAnimations to alter transparency
  72. alphaDown = new AlphaAnimation(1f, 1f);
  73. alphaDown.setDuration(1000);
  74. alphaDown.setFillAfter(true);
  75.        
  76. //Assigns the buttons and stats panels defined in the layout xml to their appropiate java arrays. Also sets clickListeners to buttons.
  77.     for(int i = 0; i < 10; i++)
  78.     {
  79.         seatButton[i] = (ImageButton) findViewById(getResources().getIdentifier("imageButton" + (i+1), "id", "en.deco.android.livehud"));
  80.         seatStats[i] = (TextView) findViewById(getResources().getIdentifier("textView" + (i+1), "id", "en.deco.android.livehud"));
  81.         seatButton[i].setOnLongClickListener(longClickListener);
  82.         seatButton[i].startAnimation(alphaDown);
  83.         seatButton[i].setAlpha(80);
  84.     }