0
隨機活動完成後,如何在按鈕點擊後不再顯示?看到我下面的隨機代碼。我實在不明白它out.Thanks放棄隨機活動一旦顯示
public void onClick(View view){
Random rnd = new Random();
int x=rnd.nextInt(4)+1;
Intent intent = new Intent();
switch (x){
case 1:
intent.setClass(this,John.class);
break;
case 2:
intent.setClass(this,Caleb.class);
break;
case 3:
intent.setClass(this,Isaiah.class);
break;
case 4:
intent.setClass(this,Jacob.class);
break;
}
startActivity(intent);
}
嘿McGuile,完成()似乎沒有工作。我添加此方法的活動仍以隨機代碼形式出現。我希望在查看該活動後不再顯示該活動。因此,如果有5個活動,則在查看活動#1之後,現在只有剩餘的4個活動可以查看。我仍然在學習,所以任何幫助表示讚賞。謝謝。 – user3055624
public void onClick(View view){ Random rnd = new Random(); int x = rnd.nextInt(4)+1; Intent intent = new Intent(); switch(x){ case 1: intent.setClass(this,John.class); 休息; case 2: intent.setClass(this,Caleb.class); 休息;案例3: intent.setClass(this,Isaiah.class); 休息;案例4: intent.setClass(this,Jacob.class); 休息; } startActivity(intent); finish(); – user3055624
嗨,你可以嘗試this.finish()或getActivity.finish()? – McGuile