我想在列表视图中将用户点击的项目的详细信息显示在文本视图中。但是出于某种原因,无论我单击哪个项目,文本视图将始终只显示数据库中的一个数据。我甚至不确定这是否是正确的方法。请帮我解决这个问题。如果没有足够的信息,请告诉我。
MainActivity:
private void showDetailsDialog(final String teamName){
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.details_dialog, null);
dialogBuilder.setView(dialogView);
final TextView textViewDetails = (TextView) dialogView.findViewById(R.id.textViewDetails);
dialogBuilder.setTitle(teamName);
final AlertDialog b = dialogBuilder.create();
b.show();
databaseTeams.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
//Getting the data from snapshot
Team team = postSnapshot.getValue(Team.class);
//Adding it to a string
String string = "Team Name: "+team.getTeamName()+"\nSport: "+team.getTeamSport()+"\nTeam Leader: "+team.getTeamOwner()+
"\nDate: "+team.getDate()+"\nTime: "+team.getTime()+"\n\n";
//Displaying it on textview
textViewDetails.setText(string);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
数据库:
它将始终显示" ping"细节无论我点击哪一个。