0

我使用FirebaseIndexRecyclerAdapter和我'試圖證明後爲以下用戶,所以我用這些方法自爆,但它顯示的帖子如果帖子ID可在以下用戶:FirebaseIndexRecyclerAdapter顯示用戶名

這裏是我的JSON:

"Following" : { 
    "ORBBKfZAAUhqI1h7ojQDzYOjgkp1" : { 
     "pypD1SYZkbcYesk09WuMUY1AkTf1": true, 
     //When I add here post id it show the post ex:"-KduqnVVczZf5uibQiZ-" : true,//Post Shows Up 
    }, 
    "Posts" : { 
    "-KduqnVVczZf5uibQiZ-" : { 
     "Describe" : "gg", 
     "MostView" : -8, 
     "Time" : 14881230655, 
     "UID" : "pypD1SYZkbcYesk09WuMUY1AkTf1", 
     "Username" : "Jone", 
     "Wallpaper" : "https://firebasestorage.googleapis.com/v0/b/test-3f4c5.appspot.com/o/Posts%2Fcropped906285501.jpg?alt=media&token=0c1a3a3d-6e48-4c4e-ba59-f5646bf8965f" 
    }, 
    "-Ke5gJ00CxbjhOuhzLIx" : { 
     "Describe" : "hajj", 
     "MostView" : -9, 
     "Time" : 1488318465, 
     "UID" : "pypD1SYZkbcYesk09WuMUY1AkTf1", 
     "Username" : "Dom", 
     "Wallpaper" : "https://firebasestorage.googleapis.com/v0/b/test-3f4c5.appspot.com/o/Posts%2Fcropped1717103943.jpg?alt=media&token=a85b2488-5ac7-49a7-9ad0-dbf4e6f29389" 
    }, 
    "-KeCuiFmUCpN19zwsTsR" : { 
     "Describe" : "a", 
     "MostView" : -2, 
     "Profile" : "https://lh4.googleusercontent.com/-suB77riNoX8/AAAAAAAAAAI/AAAAAAAAAAA/ADPlhfKMzINn-Ki538Sqf6SRGaXC81-WuQ/s200-c/photo.jpg", 
     "Time" : 1488439652, 
     "UID" : "z2SNUlLd6mQM8nnlkU2VUws5Ggl2", 
     "Username" : "Dom", 
     "Wallpaper" : "https://firebasestorage.googleapis.com/v0/b/test-3f4c5.appspot.com/o/Posts%2Fcropped1913886685.jpg?alt=media&token=c8ad26b2-8f09-453b-b48a-aad9e4d8b5c3" 
    }, 
    "-KeD2fBUQ09HVMrvAneb" : { 
     "Describe" : "ee", 
     "MostView" : -2, 
     "Profile" : "https://lh4.googleusercontent.com/-suB77riNoX8/AAAAAAAAAAI/AAAAAAAAAAA/ADPlhfKMzINn-Ki538Sqf6SRGaXC81-WuQ/s200-c/photo.jpg", 
     "Time" : 1488441999, 
     "UID" : "z2SNUlLd6mQM8nnlkU2VUws5Ggl2", 
     "Username" : "Dom", 
     "Wallpaper" : "https://firebasestorage.googleapis.com/v0/b/test-3f4c5.appspot.com/o/Posts%2Fcropped1904338270.jpg?alt=media&token=d200b7fc-15e7-4dc4-9913-59c377929e9e" 
    }, 
    "-KeDfnMWiB7k_4J3FBgZ" : { 
     "Describe" : "f12g", 
     "MostView" : -1, 
     "Time" : 1488452517, 
     "UID" : "ORBBKfZAAUhqI1h7ojQDzYOjgkp1" 
     "Username" : "Young", 
     "Wallpaper" : "https://firebasestorage.googleapis.com/v0/b/test-3f4c5.appspot.com/o/Posts%2Fcropped1872832638.jpg?alt=media&token=80239844-a872-47e2-9689-92d368dd9452" 
    }, 
    "-KeDfrw4inUQFtIDXJHp" : { 
     "Describe" : "fg", 
     "MostView" : -2, 
     "Time" : 1488452536, 
     "UID" : "ORBBKfZAAUhqI1h7ojQDzYOjgkp1" 
     "Username" : "Young", 
     "Wallpaper" : "https://firebasestorage.googleapis.com/v0/b/test-3f4c5.appspot.com/o/Posts%2Fcropped1872832638.jpg?alt=media&token=80239844-a872-47e2-9689-92d368dd9452" 
    }, 

    } 
} 

這是我的方法,我用:

mAuth = FirebaseAuth.getInstance(); 
    mCurrentUser = mAuth.getCurrentUser(); 
    mDatabase = FirebaseDatabase.getInstance().getReference().child("Posts"); 
    mDatabaseFriends = FirebaseDatabase.getInstance().getReference().child("Following").child(mCurrentUser.getUid()); 

    FirebaseIndexRecyclerAdapter<Getting_Posts,PostViewHolder> firebaseIndexRecyclerAdapter = new FirebaseIndexRecyclerAdapter<Getting_Posts, PostViewHolder>(
      Getting_Posts.class,R.layout.post_card_design,PostViewHolder.class,mDatabaseFriends,mDatabase.orderByChild("Username")) 
    { 
     @Override 
     protected void populateViewHolder(PostViewHolder viewHolder, Getting_Posts model, int position) {}}; 

我用orderByChild方法與mDatabase,但它不工作所以我需要通過用戶名排序或排序我的帖子,所以我找不到可用於此的正確查詢。

回答

1

你可以申請通過更新你的代碼像下面的排序:

FirebaseDatabase.getInstance().getReference().child("Following").child(mCurrentUser.getUid()).orderByChild("Username"); 

檢查火力地堡文檔的Sort data

+0

好@pRaNaY,以及有關顯示只有以下用戶 – 7uthaifah

+0

上面也提到該鏈接的職位是什麼包括如何過濾數據。在這種情況下,你想通過裏面的'uid'數據過濾'Post'的數據,對吧? – koceeng

+0

對不起兄弟,但我現在還不能解決問題。 – 7uthaifah