私のアプリに別の問題が発生しました。猫が死んだとき、私は "結果画面"を打ちました(新しい活動ではありませんが、現在の要素をすべて隠し、死因を示す新しいテキストビューを表示します)。メニュー項目を非表示にしたいのですが、それがisHeDead()
に応答しない理由です。私はそれを偽に設定しないとメニューが表示されます
基本的に問題は、何らかの理由でisHeDead()
が他の場所で動作していても動作していないため、onCreateOptionsMenu
の中に "return false"が表示されないようです。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(fab_menu, menu);
while (!isHeDead()){
return true;
}
return false;
}
public Boolean isHeDead() {
TextView t = (TextView) findViewById(R.id.textDiedOf);
TextView textName = (TextView) findViewById(R.id.CatsTitleStats);
TextView textAge = (TextView) findViewById(R.id.CatsAgeStat);
TextView textStats1 = (TextView) findViewById(R.id.CatsStats);
TextView textStats2 = (TextView) findViewById(R.id.CatsStats2);
ImageView image = (ImageView) findViewById(R.id.imageViewCat);
if (cat.getAge() >= 20) {
textName.setVisibility(View.GONE);
textAge.setVisibility(View.GONE);
textStats1.setVisibility(View.GONE);
textStats2.setVisibility(View.GONE);
image.setVisibility(View.GONE);
t.setText("Sorry! " + getIntent().getStringExtra(KEY_NAME_EXTRA) + " died of old age.");
return true;
} else if (cat.getAnger() >= 10) {
textName.setVisibility(GONE);
textAge.setVisibility(View.GONE);
textStats1.setVisibility(View.GONE);
textStats2.setVisibility(View.GONE);
image.setVisibility(View.GONE);
t.setText("Sorry! " + getIntent().getStringExtra(KEY_NAME_EXTRA) + " died of madness.");
return true;
} ///etc...
}
ユーザオプション(これはメニューの問題と関係があるかどうかは不明ですが)。
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
/// FEED ///
case R.id.action_feed:
int qualityRandom = (int) (Math.random() * 10);
if (qualityRandom == 5) {
cat.happy(-2);
cat.healthy(-30);
cat.angry(2);
cat.thirsty(2);
ageStat();
Stats1();
Stats2();
if (isHeDead()) {
break;
} else {
Toast.makeText(CatStatus.this, "Food was in a poor state...", Toast.LENGTH_SHORT).show();
break;
}
} else {
cat.happy(1);
cat.healthy(10);
cat.hungry(-3);
cat.angry(-1);
ageStat();
Stats1();
Stats2();
Toast.makeText(CatStatus.this, "Yummy!", Toast.LENGTH_SHORT).show();
break;
}
/// DRINK ///
case R.id.action_drink: ///etc...
感謝の男!今働く。しかし、この隠蔽アクションをより速くする方法はありますか?今は左に動いて消えていく様子を示しているので、ユーザーが気付かないほど速く起こったのであれば、私はそれを好むだろう。これは可能ですか、新しい活動が必要でしょうか? –
どのオプションを使用しましたか? 'menu.clear()'? –
私の意見では、私は断片と一緒に行くだろう!アクティビティを1つだけ作成してから2つのフラグメントを作成し、ユーザーがクリックして結果を表示すると、2つのフラグメント間でトランザクションを作成できます。これは、要素を隠すよりもユーザーにとって新しい画面を作るよりも賢明な解決策です。または、2つのアクティビティにも行くことができます。それは問題ありません。しかし、異なる断片/活動で画面を分離することは良いことです。 –