Greating follow Coders, I would like to ask you, because I am stucked.
Currently I working on a following page, what is similar to Instagram's follow process. In my case the app will fitch first the followed people, how you follow. If it is done, the program will start the parent recyclerview and write out the name and the profilepicture of the followed user. The second step is to fetch the followed users trainings. Until that everything works fine, but in the most cases the first recyclerview (nested)in the parents recyclerview dissapear when it has just one training inside the list. The same happens if everything is loaded correctly at the first time, but when I scroll in the horizontal child recyclerview (at that time will be created the item's view, but already fetched from the cloud) the recyclerview dissapears always. Only the first one if it has only one item.
Is there any attribute of the recyclerview, what I have to set?
Thanks for your help. Peter Pázmándi
Parent onBindViewHolder (in a fragment)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle? ): View?
{
val rootView = inflater.inflate(R.layout.news_fragment, container,
false)
firebaseViewModel =
ViewModelProviders.of(this).get(FirebaseViewModel::class.java)
FirebaseRepository.currentUserId?.let {
Log.i("$TAG.currentUserId", "${it}")
firebaseViewModel.getFollowedWithLimit(it).observe(this, Observer {
list ->
list?.let {
loadedUsers = it.size
for (i in 0..it.lastIndex)
{
if(it[i].followingUsersLastTrainingTimeStamp != 0L)
{
wholeListOfFollowers.add(it[i].followingUserId)
}
}
Log.i("$TAG.wholeList", "$wholeListOfFollowers")
rootView.recyclerView_newsfeed.apply {
recycledViewPool.setMaxRecycledViews(10,20)
layoutManager = CustomLinearLayoutManager(context!!,
LinearLayoutManager.VERTICAL, false)
adapter = NewsFeedAdapter(context, wholeListOfFollowers)
}
}
})
}
return rootView
}
Child onBindViewHolder
override fun onBindViewHolder(holder: NewsFeedViewHolder, position: Int)
{
var userId = usersId[position]
if(!fetchedUser.contains(position))
{
fetchedUser.put(position, true)
firebaseViewModel.getTrainigs(userId).observe(context as
FragmentActivity, Observer {
it?.let {trainigsList ->
if(trainigsList.size != 0)
{
firebaseViewModel.getUserByUserId(userId).observe(context,
Observer {user ->
user?.let {
trainings = trainigsList.toMutableList()
loadedTrainingSize = trainings.size
if(!user.profileImageUrl.equals(""))
{
Picasso.get()
.load(user.profileImageUrl)
.into(holder.profileIamge)
}
holder.username.text = user.name
holder.childRecyclerView.apply {
recycledViewPool.setMaxRecycledViews(0,1)
layoutManager =
CustomLinearLayoutManager(context,
RecyclerView.HORIZONTAL, false)
adapter = TrainingItemAdapter(context,
trainings)
scrollToPosition(0)
stopScroll()
}
}
})
}
else
{
Log.i("$TAG.size", "${it.size}")
holder.consraintLayout.visibility = View.GONE
}
}
})
}
else
{
Log.i("$TAG.fetchedUser", "true")
}
}