Y at-il un moyen de changer le message toast en fonction de l'ID xml du bouton qui clique dessus?changer le message toast en utilisant le commutateur
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();
}
}
Il suffit de retirer 'findViewById' de là et juste' cas R.id.spotify: ', etc et il fonctionnera comme vous vous attendez. – EpicPandaForce
Il est dit que la ligne Toast.makeText n'est pas accessible:/Elle indique également que les chaînes de toast ne sont jamais utilisées. Pouvez-vous m'aider à résoudre ce problème? –
Oui, mettez cette ligne en dehors de l'instruction switch. – EpicPandaForce