So this is my GridLayout I have declared LinearLayoutManager.VERTICAL, true
var recyclerViewUploaded: RecyclerView? = null
recyclerViewUploaded = my_posts_recycle
recyclerViewUploaded.setHasFixedSize(true)
val gridLayoutManager = GridLayoutManager(this, 2, LinearLayoutManager.VERTICAL, true )
recyclerViewUploaded.layoutManager = gridLayoutManager
postList = ArrayList()
postAdapter = MypostsAdapter(this, postList as ArrayList<Post>)
recyclerViewUploaded.adapter = postAdapter
See the above image, the problem is it leaves a blank space at the top instead of the bottom.
I have tried using Collections.reverse(postList) but it gives unexpected results the post order 123456 becomes 125643 instead of 654321.
Also postList.reverse() dosen't do anything!
Here is my function to retrive images.
private fun retrievePosts() {
val postsRef = FirebaseDatabase.getInstance().reference.child("Posts")
postsRef.addValueEventListener(object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
if (dataSnapshot.exists()) {
(postList as ArrayList<Post>).clear()
for (snapshot in dataSnapshot.children) {
val post = snapshot.getValue(Post::class.java)
if (post!!.getPublisher() == profileId) {
(postList as ArrayList<Post>).add(post)
}
if (postList.isNullOrEmpty()){
swipe_refresh_profile.isRefreshing = false
}
postList!!.reversed()
swipe_refresh_profile.isRefreshing = false
postAdapter!!.notifyDataSetChanged()
}
}
}
override fun onCancelled(error: DatabaseError) {
TODO("Not yet implemented")
}
}
)
}
Here is my JSON database structure
"Posts" : {
"-MYkL70voeqXhrkli7vE" : {
"caption" : "Setup by:- @iamlokesh_04\n\nSector Kwgt\nhttps://play.google.com/store/apps/details?id=sector.kustom.pack\n\nMini-music Kwgt\nhttps://play.google.com/store/apps/details?id=minimusicplayerforkwgt.kustom.pack\n\nSelf-made icons\nhttps://t.me/Iamlokesh_04\n\nHope you guys like it ",
"postid" : "-MYkL70voeqXhrkli7vE",
"postimage" : "https://firebasestorage.googleapis.com/v0/b/android-customization.appspot.com/o/Posted%20Pictures%2FAkZI2A4EZbMOHCHPqZp4h4hl2zL2%2F1618940031310.jpg?alt=media&token=946e7836-b032-4d95-93ac-1c04d4342161",
"publisher" : "AkZI2A4EZbMOHCHPqZp4h4hl2zL2"
},
"-MYkLhERZIZ5az-K3VrQ" : {
"caption" : "Alpplications used: #37\n\n+Launcher - Nova launcher\n\n+Widgets - https://play.google.com/store/apps/details?id=flawlesskwgt.kustom.pack \n\n+Icon Pack - https://play.google.com/store/apps/details?id=com.panotogomo.darktosca\n\n+Wallpaper - https://play.google.com/store/apps/details?id=com.stark.fluid\n\nTemplate by - https://twitter.com/vhthinh_at?s=09 ",
"postid" : "-MYkLhERZIZ5az-K3VrQ",
"postimage" : "https://firebasestorage.googleapis.com/v0/b/android-customization.appspot.com/o/Posted%20Pictures%2FAkZI2A4EZbMOHCHPqZp4h4hl2zL2%2F1618940184176.jpg?alt=media&token=f6ced789-be42-4d72-873f-8316ce557ff9",
"publisher" : "AkZI2A4EZbMOHCHPqZp4h4hl2zL2"
},
"-MYkLpNkeHPEWwmYDgwN" : {
"caption" : "Rate my Setup!! ",
"postid" : "-MYkLpNkeHPEWwmYDgwN",
"postimage" : "https://firebasestorage.googleapis.com/v0/b/android-customization.appspot.com/o/Posted%20Pictures%2FAkZI2A4EZbMOHCHPqZp4h4hl2zL2%2F1618940216883.jpg?alt=media&token=59c0b67e-bd5c-4b6c-9c14-36e16676bf58",
"publisher" : "AkZI2A4EZbMOHCHPqZp4h4hl2zL2"
}
]
Here if the posts have the publisherid same as the profile id get added into the postList List.
I am finding a solution for this for a long time, any help would be appreciated!