我花了几个小时试图做到这一点,但我一直在循环运行,我无法正确地从防火墙中获取数据。
我的android应用:
我的问题是..。
在加载活动时,如何将它们已经存储的点放入textView?
这是我有的东西

这是我的保存功能:
private void savePoints(){
String points = editTextPoints.getText().toString().trim();
UserPoints userPoints = new UserPoints(points);
FirebaseUser user = firebaseAuth.getCurrentUser();
final DatabaseReference userRef = databaseReference.child(user.getUid());
userRef.setValue(userPoints);
Toast.makeText(this, "Points Saved...", Toast.LENGTH_SHORT).show();
}这是我的UserPoints课程:
public class UserPoints {
public String points;
public UserPoints(String points) {
this.points = points;
}
public UserPoints(){ }
}现在..。有关于如何构建loadPoints的建议吗?这样用户就可以看到他有多少点了?
谢谢
发布于 2017-02-26 03:41:47
据我所知,您正在将您的听者附加到错误的位置:
private void savePoints(){
//editTextPoints is my editText field
String points = editTextPoints.getText().toString().trim();
UserPoints userPoints = new UserPoints(points);
FirebaseUser user = firebaseAuth.getCurrentUser();
final DatabaseReference userRef = databaseReference.child(user.getUid());
userRef.setValue(points);
userRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String value = dataSnapshot.getValue(String.class);
retrievePoints.setText(value);
}
@Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException(); // don't just ignore errors
}
});
}我希望你把听者附加到别的地方。现在,它将获得与您刚才编写的值相同的值,因此,您最好直接将点设置为文本视图,而不需要侦听器:
retrievePoints.setText(points);https://stackoverflow.com/questions/42464111
复制相似问题