私は、チャレンジを完了するためにポイントで授与されるアプリケーションで作業しています。今のところ、ユーザーは完了したチャレンジごとに10ポイントを獲得しています。しかし、ユーザーがチャレンジを完了するたびにユーザースコアが更新されるようにする必要があります。つまり、ポイントはデータベースから取得され、追加ポイントが追加されます。 (ユーザIDがユーザIDと一致するところでポイントを更新する必要があります)firebaseの特定の値を取得して更新する方法
どのように私はこの問題に近づくことができましたか?
public void stopActivity(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Confirm");
builder.setMessage("Are you sure you want to stop?");
builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Get the activity results
String speedText = speedTxt.getText().toString();
String distanceText = distanceTxt.getText().toString();
String timeText = timeTxt.getText().toString();
Toast.makeText(getApplicationContext(),"Your result is: " + "\n" + speedText + "\n" + distanceText + "\n" + timeText, Toast.LENGTH_LONG).show();
//if the result is better
if(Double.parseDouble(speed_challege) == Double.parseDouble(speedText) || Double.parseDouble(speed_challege) < Double.parseDouble(speedText)){
Toast.makeText(getApplicationContext(),"You completed the challenge", Toast.LENGTH_LONG).show();
//award points if challenge is completed
final DatabaseReference newResult = leaderBoard.push();
String username = mCurrentUser.getEmail();
//trim email leaving just username
int index = username.indexOf('@');
username = username.substring(0,index);
newResult.child("UserName").setValue(username);
newResult.child("uID").setValue(mAuth.getCurrentUser().getUid());
newResult.child("Score").setValue(score);
}
//if result is worse
else{
Toast.makeText(getApplicationContext(),"Hard Luck Try again", Toast.LENGTH_LONG).show();
}
dialog.dismiss();
}
});
あなたのleaderbord変数の参照先は何ですか? –
DatabaseReference mRootRef = FirebaseDatabase.getInstance()。getReference(); DatabaseReference leaderBoard = mRootRef.child( "Leaders");最終的なDatabaseReference newResult = leaderBoard.push(); – MariusBrave