0
這裏是我的情況,如果用戶在列表視圖中是該團隊的團隊成員,當他長時間點擊團隊時,會出現一個對話框。但是,如果他不是,那麼什麼都不會發生。我設法在用戶創建團隊後顯示對話框,但是當我用同一個帳戶註銷並登錄時,即使我是teamOwner,當我長時間點擊它時,對話框也不會再出現。我將用戶的電子郵件存儲爲teamOwner。我的代碼在下面,讓我知道你是否需要更多的信息。重新登錄後,Firebase對話框將不會出現
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; }
}
數據庫: