- Why does setAlpha() act on all my buttons whilst setImageResource() acts on just one button?
- seatButton[i].setAlpha(255);
- seatButton[i].setImageResource(0x7f020007)
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- table = new Table(); //Creates Table
- seatButton = new ImageButton[10]; //Creates Array of buttons
- seatStats = new TextView[10]; //Creates array for stat panels
- //Creates longClickListener, used for players to sit in or out.
- longClickListener = new View.OnLongClickListener()
- {
- @Override
- public boolean onLongClick(View v)
- {
- for(int i=0; i<10; i++)
- {
- //Each seat[i] will correspond with each imageButtoni+1
- if(v.getId() == (getResources().getIdentifier("imageButton" + (i+1), "id", "en.deco.android.livehud")))
- {
- //If the seat is empty fill it, place a player in the seat and change the button from translucent to opaque
- if(table.seats[i].getState().equals("empty"))
- {
- seatButton[i].setAlpha(255);
- //seatButton[i].setImageResource(0x7f020000);
- table.seats[i].sit(new Player());
- seatStats[i].setVisibility(View.VISIBLE);
- Toast.makeText(GUI.this, table.seats[i].getState(), Toast.LENGTH_SHORT).show();
- }
- //If the seat is full, empty it
- else
- {
- seatButton[i].setAlpha(80);
- //seatButton[i].setImageResource(0x7f020007);
- table.seats[i].sitOut();
- seatStats[i].setVisibility(View.INVISIBLE);
- Toast.makeText(GUI.this, table.seats[i].getState() + i, Toast.LENGTH_SHORT).show();
- }
- }
- }
- return true;
- }
- };
- //Assigns the buttons and stats panels defined in the layout xml to their appropiate java arrays. Also sets clickListeners to buttons.
- for(int i = 0; i < 10; i++)
- {
- seatButton[i] = (ImageButton) findViewById(getResources().getIdentifier("imageButton" + (i+1), "id", "en.deco.android.livehud"));
- seatStats[i] = (TextView) findViewById(getResources().getIdentifier("textView" + (i+1), "id", "en.deco.android.livehud"));
- seatButton[i].setOnLongClickListener(longClickListener);
- seatButton[i].setAlpha(80);
- }
- if(table.seats[i].getState() == "empty") { ... }
- if(table.seats[i].getState().equals("empty")) { ... }
- //Initializes AlphaAnimations to alter transparency
- alphaDown = new AlphaAnimation(1f, 1f);
- alphaDown.setDuration(1000);
- alphaDown.setFillAfter(true);
- //Assigns the buttons and stats panels defined in the layout xml to their appropiate java arrays. Also sets clickListeners to buttons.
- for(int i = 0; i < 10; i++)
- {
- seatButton[i] = (ImageButton) findViewById(getResources().getIdentifier("imageButton" + (i+1), "id", "en.deco.android.livehud"));
- seatStats[i] = (TextView) findViewById(getResources().getIdentifier("textView" + (i+1), "id", "en.deco.android.livehud"));
- seatButton[i].setOnLongClickListener(longClickListener);
- seatButton[i].startAnimation(alphaDown);
- seatButton[i].setAlpha(80);
- }