likeカウンタを取得し、firebaseデータベースに結果をアップロードしたいと考えています。別のユーザーがポストを気に入った場合のようなカウンタは、私がinTransactionマネージャブーティを使用していlolCounter値ではなく、更新には0から始まるfirebaseの複数のユーザーのカウントを同じように管理したい
DatabaseLOLCounter.child(post_key).child(mAuth.getCurrentUser().getUid()).child("counter").setValue('like counter value here');
以下
私viewholderある
viewHolder.mLOL.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
processLOL=true;
DatabaseFacepalm.child(post_key).child(mAuth.getCurrentUser().getUid()).removeValue();
DatabaseAngry.child(post_key).child(mAuth.getCurrentUser().getUid()).removeValue();
DatabaseNeutral.child(post_key).child(mAuth.getCurrentUser().getUid()).removeValue();
DatabaseLOL.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (processLOL)
{
if(dataSnapshot.child(post_key).hasChild(mAuth.getCurrentUser().getUid()))
{
//Toast.makeText(MainActivity.this,mAuth.getCurrentUser().getUid(),Toast.LENGTH_LONG).show();
//if already reacted
//DatabaseLOLCounter.setValue(Count = Count - 1);
updateLOLCounter(false,post_key);
DatabaseLOL.child(post_key).child(mAuth.getCurrentUser().getUid()).removeValue();
processLOL=false;
}
else
{
//if no react
updateLOLCounter(true,post_key);
//DatabaseLOLCounter.setValue(Count = Count + 1);
DatabaseLOL.child(post_key).child(mAuth.getCurrentUser().getUid()).setValue("lol");
processLOL=false;
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
は知らないインクリメントすべきですどのようにsesultsを取得する方法とそれをデータベースに格納するには、私は試してみましたが、それは動作していない、私を修正してください。
private void updateLOLCounter(final boolean increment, final String post_key) {
DatabaseLOLCounter.runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(MutableData mutableData) {
if (mutableData.getValue() != null) {
int value = mutableData.getValue(Integer.class);
if(increment)
{
value++;
} else {
value--;
}
mutableData.setValue(value);
}
return Transaction.success(mutableData);
}
@Override
public void onComplete(DatabaseError databaseError, boolean b,
DataSnapshot dataSnapshot) {
// Is the below method is right?
DatabaseLOLCounter.child(post_key).child(mAuth.getCurrentUser().getUid()).child("counter").setValue(dataSnapshot);
// Toast.makeText(MainActivity.this,dataSnapshot,Toast.LENGTH_LONG).show();
// Transaction completed
//Log.d(TAG, "likeTransaction:onComplete:" + databaseError);
}
});
}
コンソールは私にエラー「TransactionTooLargeException」を与えている活動との意図にあまりにも多くのデータを渡すときに
私の問題の解決方法はありますか? –