我有2个DatabaseReference:
我想让孩子从“活跃”到“完成”,但我无法做到。有什么想法?感谢。
我有这段代码:
public class SingleGameActivity extends AppCompatActivity {
private DatabaseReference mDatabaseActivGame;
private DatabaseReference mDatabaseFinishGame;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_game);
game_key = getGameKey();
mDatabaseActivGame = FirebaseDatabase.getInstance().getReference().child("Games").child("Active").child(game_key);
mDatabaseGame.keepSynced(true);
mDatabaseFinishGame = FirebaseDatabase.getInstance().getReference().child("Games").child("Finish").child(game_key);
mDatabaseGame.keepSynced(true);
...
在活跃儿童中,我有game_key
及其内部多个子值。
我想将它移动完成,因为recyclerview向我展示了活跃的孩子。谢谢!
答案 0 :(得分:0)
以下代码将从ClassMap
"your-project-root/Games/Active/game_key"
然后,以下代码将在// mDatabaseActivGame is still the same like in your sample
mDatabaseActivGame.addListenerForSingleValueEvent(new ValueEventListener() {
... onDataChange(DataSnapshot dataSnapshot) {
// data is in dataSnapshot object
// do something here
}
...
});
"your-project-root/Games/Finish/game_key"
所以结合它们我们得到这样的代码:
// mDatabaseFinishGame is still the same like in your sample
mDatabaseFinishGame.setValue(yourValueHere);
我自己没有测试过,但理论上它应该可行。希望这有帮助