有沒有什麼辦法可以根據點擊它的按鈕的xml id來更改吐司消息?使用開關更改吐司消息
public void toast (View view) {
String toast ="";
switch (view.getId()) {
case findViewById(R.id.spotify): toast = "Spotify streamer will show here";
break;
case findViewById(R.id.scores): toast = "Scores app will show here";
break;
case findViewById(R.id.library): toast = "March";
break;
case findViewById(R.id.build): toast = "Build app will show here";
break;
case findViewById(R.id.xyz): toast = "XYZ Reader app will show here";
break;
case findViewById(R.id.capstone): toast = "My Capstone app will show here";
break;
Toast.makeText(this, toast, Toast.LENGTH_SHORT).show();
}
}
剛剛從那裏取出'findViewById',只是有'情況R.id.spotify:'等,也將努力爲你的期望。 – EpicPandaForce
它表示Toast.makeText行不可訪問:/它還表示從不使用Toast字符串。你能幫我解決這個問題嗎? –
是的,把這條線放在switch語句之外。 – EpicPandaForce