からデータを取得するには、正しい要素を返さない場合:文が、私はこのようになります<code>FirebaseDatabase</code>でいくつかのデータ持っfirebase
public void fMethod(final String fID, final String blackListedId) {
mDatabase.child("child1").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.getValue() != null) {
Profile profile = dataSnapshot.getValue(Profile.class);
String pID = profile.getPID();
String lID = profile.getLID();
if (!pID.trim().equals(AccessToken.getCurrentAccessToken().getUserId().trim())) {
if (pID.trim().equals(fID.trim())) {
if (!lID.trim().equals(blackListedId.trim())) {
// populate the view with elements which meet this condition/requirement
String listingID = profile.getlID();
Log.d("LISTING_IDS", listingID);
} else {
Log.d("dataSnapshot", "null1");
}
} else {
Log.d("dataSnapshot", "null2");
}
} else {
Log.d("dataSnapshot", "null3");
}
} else {
Log.d("dataSnapshot", "null4");
}
}
...
...
...
}
:私はこのような
child1
のデータを取得しています
app
-child1
-uniqueId1
-pId1
-lId1
-uniqueId2
-pId2
-lId2
-uniqueId3
-pId3
-lId3
-uniqueId4
-pId4
-lId4
-uniqueId5
-pId5
-lId5
-uniqueId6
-pId6
-lId6
-child2
-uniqueIdA1
-uniqueId7
-uniqueId8
-uniqueId9
-uniqueId10
-uniqueId11
-uniqueId1
-uniqueId2
-uniqueId3
-uniqueId4
-uniqueId5
をこのような
とchild2
のデータ:
public void fData(final String fID) {
mDatabase.child("child2").child(AccessToken.getCurrentAccessToken().getUserId()).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.getValue() != null) {
for (DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
String blackListedId = childSnapshot.getValue().toString();
fMethod(fID, blackListedId);
}
} else {
fMethod(fID, "");
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
、その後、別のコードで私はfID
を取得しており、そこでfData()
メソッドを呼び出しています。
私はすべてのIDS私は、データベースから取得していログイン:
D/LISTING_IDS: uniqueId1
D/LISTING_IDS: uniqueId1
D/LISTING_IDS: uniqueId1
D/LISTING_IDS: uniqueId1
D/LISTING_IDS: uniqueId1
D/LISTING_IDS: uniqueId1
D/LISTING_IDS: uniqueId1
D/LISTING_IDS: uniqueId1
D/LISTING_IDS: uniqueId1
D/LISTING_IDS: uniqueId2
D/LISTING_IDS: uniqueId2
D/LISTING_IDS: uniqueId2
D/LISTING_IDS: uniqueId2
D/LISTING_IDS: uniqueId2
D/LISTING_IDS: uniqueId2
D/LISTING_IDS: uniqueId2
D/LISTING_IDS: uniqueId2
D/LISTING_IDS: uniqueId2
D/LISTING_IDS: uniqueId3
D/LISTING_IDS: uniqueId3
D/LISTING_IDS: uniqueId3
D/LISTING_IDS: uniqueId3
D/LISTING_IDS: uniqueId3
D/LISTING_IDS: uniqueId3
D/LISTING_IDS: uniqueId3
D/LISTING_IDS: uniqueId3
D/LISTING_IDS: uniqueId3
D/LISTING_IDS: uniqueId4
D/LISTING_IDS: uniqueId4
D/LISTING_IDS: uniqueId4
D/LISTING_IDS: uniqueId4
D/LISTING_IDS: uniqueId4
D/LISTING_IDS: uniqueId4
D/LISTING_IDS: uniqueId4
D/LISTING_IDS: uniqueId4
D/LISTING_IDS: uniqueId4
D/LISTING_IDS: uniqueId5
D/LISTING_IDS: uniqueId5
D/LISTING_IDS: uniqueId5
D/LISTING_IDS: uniqueId5
D/LISTING_IDS: uniqueId5
D/LISTING_IDS: uniqueId5
D/LISTING_IDS: uniqueId5
D/LISTING_IDS: uniqueId5
D/LISTING_IDS: uniqueId5
ここProfile.java
ファイルのコードです:https://gist.github.com/HammadNasir/a196bcdc6dccbf69657fca528443e680
問題はfMethod()
年代に条件がとても!lID.trim().equals(blackListedId.trim()
あるif文ということです、あなたがデータベースで見ることができるように、uniqueId
をchild1
に、uniqueId3
とuniqueId7
以外はchild2
にあるので、私はすべてuniqueId
を除き、uniqueId3
およびuniqueId7
を2回、uniqueId3
およびuniqueId7
を1回とします。注意すべき
もう一つは、私がlID.trim().equals(blackListedId.trim()
としてその状態を作っているとき、私は、この要件に合致のみ2つのIDを取得すなわち、uniqueId3
とuniqueId7
とchild2
はuniqueId11
の下でのみ1 IDを持っているならば、私は」だということですuniqueId
がここにあるものを除いて2つ以上のIDを持つことが問題を引き起こしています。
私はあなたの問題を願っています。私は可能な限り少ないコードで説明しようとしました。
なぜ!lID.trim().equals(blackListedId.trim()
が予期しないIDを返すのですか?この条件を満たすIDのみを取得するにはどうすればよいですか?
@IbrahimはFirebaseをよく知らないのですか? –
あなたのケースは、firebaseスキルに依存しないと思っています。デバッグスキルにもっと依存しています。値のデバッグを試してみて、条件を確認してください。これは最も速い解決策です。 – Ibrahim
サーバから取得したすべての情報を記録します。次にコードと共にlogcatを投稿します。 –