在我的情况下,如果用户是列表视图中该团队的团队成员,当他长按团队时,会出现一个对话框。但是,如果他不是,那么什么都不会发生。我设法在用户创建团队后显示对话框,但是当我注销并使用相同的帐户登录时,即使我是teamOwner,当我长按它时对话框也不会出现。我将用户的电子邮件存储为teamOwner。我的代码如下所示,如果您需要更多信息,请与我们联系。
MainActivity:
listViewTeams.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
FirebaseUser user = firebaseAuth.getCurrentUser();
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
Team team = teams.get(i);
String owner = user.getEmail();
if (owner == team.getTeamOwner()) {
showUpdateDeleteDialog(team.getTeamId(), team.getTeamName());
}
else{
}
return true;
}
});
AddActitvity:
private void addTeam() {
//getting the values to save
String name = editTextName.getText().toString().trim();
String sport = spinnerSport.getSelectedItem().toString();
String date = textDate.getText().toString();
String time = textTime.getText().toString();
FirebaseUser user = firebaseAuth.getCurrentUser();
user.getEmail();
//checking if the value is provided
if (!TextUtils.isEmpty(name)) {
//getting a unique id using push().getKey() method
//it will create a unique id and we will use it as the Primary Key for our Team
String id = databaseTeams.push().getKey();
String owner = user.getEmail();
String member = user.getEmail();
//creating an Team Object
Team team = new Team(id, name, sport, owner, date, time);
Member members = new Member(member);
//Saving the Team
databaseTeams.child(name).setValue(team);
databaseMembers.child(name).setValue(members);
//setting edittext to blank again
editTextName.setText("");
//displaying a success toast
Toast.makeText(this, "Team added", Toast.LENGTH_LONG).show();
} else {
//if the value is not given displaying a toast
Toast.makeText(this, "Please enter a name", Toast.LENGTH_LONG).show();
}
}
Team.java
public class Team {
private String teamId;
private String teamName;
private String teamSport;
private String teamOwner;
private String date;
private String time;
public Team() {
}
public Team(String teamId, String teamName, String teamSport, String teamOwner, String date, String time) {
this.teamId = teamId;
this.teamName = teamName;
this.teamSport = teamSport;
this.teamOwner = teamOwner;
this.date = date;
this.time = time;
}
public String getTeamId() {return teamId;}
public String getTeamName() {
return teamName;
}
public String getTeamSport() {
return teamSport;
}
public String getTeamOwner() { return teamOwner; }
public String getDate(){ return date; }
public String getTime() { return time; }
}
数据库:
答案 0 :(得分:0)
好的我觉得我找到了问题的解决方案。在我的主要活动中,我使用'=='而不是.equals(),这是不推荐的。