【发布时间】:2020-03-29 19:04:45
【问题描述】:
我试图弄清楚如何在这个 switch 语句中将一个字符串放入一个 case 标签中,这样它也可以在其他语言中工作。这是我目前的代码。
或者如果有更好的编码方式,那么当使用其他语言时,按钮仍然可以工作
if (profileid.equals(firebaseUser.getUid())) {
edit_profile.setText(R.string.edit_Profile_Button);
} else {
checkFollow();
saved_photos.setVisibility(View.GONE);
my_photos.setVisibility(View.GONE);
}
edit_profile.setOnClickListener(v -> {
String btn = edit_profile.getText().toString();
switch (btn) {
case "Edit Profile":
startActivity(new Intent(getContext(), EditProfileActivity.class));
break;
case "support":
FirebaseDatabase.getInstance().getReference().child("Support").child(firebaseUser.getUid())
.child("supporting").child(profileid).setValue(true);
FirebaseDatabase.getInstance().getReference().child("Support").child(profileid)
.child("supporters").child(firebaseUser.getUid()).setValue(true);
addNotifications();
break;
case "supporting":
FirebaseDatabase.getInstance().getReference().child("Support").child(firebaseUser.getUid())
.child("supporting").child(profileid).removeValue();
FirebaseDatabase.getInstance().getReference().child("Support").child(profileid)
.child("supporters").child(firebaseUser.getUid()).removeValue();
break;
}
});
【问题讨论】:
标签: java android firebase switch-statement