gpt4 book ai didi

java - 使用 switch 更改 toast 消息

转载 作者:行者123 更新时间:2023-12-01 07:52:13 25 4
gpt4 key购买 nike

有什么方法可以根据单击按钮的 xml id 更改 toast 消息吗?

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();
}
}

最佳答案

只需使用 case R.id.spotify: 而不是 case findViewById(R.id.spotify): 等...

关于java - 使用 switch 更改 toast 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35356750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com