もう一度アドバイスが必要です。
最後のハードルで立ち往生していますが、私が取り組んでいるこのモジュールは 99% 完了しています。実行時に画面にボタンを動的に公開しています。このボタンを押すと、新しいアクティビティ ビューが表示されます。私はそれを完全に機能させました。
ただし、ビューをランダムに変更する別のボタンがあるため、それが理にかなっている場合は、効果的にリセットする必要があります。ボタン (動的ボタン) がクリックされるたびに、別のボタンがスタックに追加されます。事実上、画面を下にクリックするたびにボタンがあります。私のロジックは間違っていますか、それともボタンが毎回表示されるのをチェックして防ぐ方法はありますか? つまり、一度だけ...以下はコードです。
public void ButtonOnClick(View v) {
Random rnd = new Random();
int randomListIndex = rnd.nextInt(2);
Animation myFadeInAnimation = AnimationUtils.loadAnimation(Page1.this, R.anim.fadein);
int firstRun = 0;
switch (randomListIndex) {
case 0:
//get the image your going to muck with
image = (ImageView) findViewById(R.id.cardImageView);
//set the image with what it should be
image.setImageResource(R.drawable.storm);
//apply the transition effect so it looks correct
image.startAnimation(myFadeInAnimation);
button = (Button)findViewById(R.id.dynamicButton);
button.setText("Need another question?");
Button myButton = new Button(this);
myButton.setText("Press Me");
LinearLayout layout = (LinearLayout) findViewById(R.id.nextPageContainer);
layout.addView(myButton);
final Button myButton1 = myButton;
myButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0) {
String activityName = "Storm";
Intent intent = new Intent(Page1.this, Page2.class);
intent.putExtra(ACTIVITYNAME,activityName);
startActivity(intent);
}
});
break;
}
}