我一直在寻找一段时间来帮助我解决我的问题,但找不到任何好的教程。我最近开始使用Android,所以我不是那么好。我的问题是如何以一种不必输入所有内容的方式转换我的代码。我在想也许可以使用计数器。我想知道是否有可能只需要设置一次搜索栏和按钮的可见性。这是我的代码:
private void numberPlayers() {
Intent intent = getIntent();
String str = intent.getStringExtra("rbPlayers");
if (str.equals("rb2")) {
sbPlayer3.setVisibility(View.GONE);
bPlus3.setVisibility(View.GONE);
sbPlayer4.setVisibility(View.GONE);
bPlus4.setVisibility(View.GONE);
sbPlayer5.setVisibility(View.GONE);
bPlus5.setVisibility(View.GONE);
sbPlayer6.setVisibility(View.GONE);
bPlus6.setVisibility(View.GONE);
} else if (str.equals("rb3")) {
sbPlayer4.setVisibility(View.GONE);
bPlus4.setVisibility(View.GONE);
sbPlayer5.setVisibility(View.GONE);
bPlus5.setVisibility(View.GONE);
sbPlayer6.setVisibility(View.GONE);
bPlus6.setVisibility(View.GONE);
} else if (str.equals("rb4")) {
sbPlayer5.setVisibility(View.GONE);
bPlus5.setVisibility(View.GONE);
sbPlayer6.setVisibility(View.GONE);
bPlus6.setVisibility(View.GONE);
} else if (str.equals("rb5")) {
sbPlayer6.setVisibility(View.GONE);
bPlus6.setVisibility(View.GONE);
}
}
先感谢您!