0
私は人生を表示するためにテキストのない12個のボタンを使用しているゲームを持っています。彼らは命を失うたびに、このコードはボタンを透明にしてから再び不透明にしてください。
public void guessesRemainingDisplay(int numberOfGuesses) {
int guessesRemaining;
guessesRemaining = maximumGuesses + 1 - numberOfGuesses;
switch(guessesRemaining) {
case 1:
findViewById(R.id.Guess1).setBackgroundColor(color.transparent);
break;
case 2:
findViewById(R.id.Guess2).setBackgroundColor(color.transparent);
break;
case 3:
findViewById(R.id.Guess3).setBackgroundColor(color.transparent);
break;
case 4:
findViewById(R.id.Guess4).setBackgroundColor(color.transparent);
break;
case 5:
findViewById(R.id.Guess5).setBackgroundColor(color.transparent);
break;
case 6:
findViewById(R.id.Guess6).setBackgroundColor(color.transparent);
break;
case 7:
findViewById(R.id.Guess7).setBackgroundColor(color.transparent);
break;
case 8:
findViewById(R.id.Guess8).setBackgroundColor(color.transparent);
break;
case 9:
findViewById(R.id.Guess9).setBackgroundColor(color.transparent);
break;
case 10:
findViewById(R.id.Guess10).setBackgroundColor(color.transparent);
break;
case 11:
findViewById(R.id.Guess11).setBackgroundColor(color.transparent);
break;
case 12:
findViewById(R.id.Guess12).setBackgroundColor(color.transparent);
break;
}
}
を実行され、遠い最も右ボタンが消滅(彼らは上の1が右側に12を左ライン、です)。
しかし、私は新しいゲームを開始するか、活動が最初に開いたときに、このコードは
一つ一つのIDに対して繰り返さfindViewById(R.id.Guess1).setBackgroundColor(color.X);
を実行したとき。 Xは文字どおりの色です(私はさまざまなものを試してみました)。何らかの理由で、このコードが実行されると、ボタンは消えます。どうして?それが実行されない場合は、12のボタンが表示されますが、私は新しいゲームを開始するたびに、人生を失って消滅したボタンは戻ってきません。
ありがとうございます!それは完璧に働いた –