At the moment my buttons do not work. The first two times any are pressed all buttons are influenced rather than just the one that has been pressed.
Swap:
seatButton[i].setAlpha(255);
For:
seatButton[i].setImageResource(0x7f020007)
And my code works! Only the button I press is effected. Why?
@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);
}