Issue
Hi I am using android studio and I am currently working with recyclerview the thing is that I wanted to get show a hidden ImageView behind the row when is swiped, but because I don't know how.
I've come with the idea of using two linear layout so one of it will storage the recyclerview with the images, and the other the recyclerview with the swiping rows.
Is this posible? Could this slower the application? It is a waste of memory ?
Thank you in advance
Solution
I'm working under the assumption that you have some custom view inside of your viewHolders, and that you use onBindViewHolder to populate that view for each position. Which is to say that I'm working under the assumption that you have something like the following for ViewHolder construction:
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
var myCustomView= view as MyCustomView
}
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
val myCustomView=MyCustomView(viewGroup.context)
myCustomView.layoutParams= ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT)
return ViewHolder(myCustomView)
}
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
viewHolder.myCustomView.myTextView.text="this is text"
}
If I had to solve this problem, I would go the xml for to that custom view and wrap on the most exterior level with a FrameLayout or a LinearLayout. So now your onBindViewHolder is doing pretty much the same job, except that it's populating all of the content like viewHolder.myCustomView.interior.myTextView.text="this is text" instead of viewHolder.myCustomView.myTextView.text="this is text".
Then I would extend ItemTouchHelper.Callback(), which gives you a swipe listener. And inside of that swipe listener, I would remove the interior of myCustomView and replace it with an imageView. Then I would call notifyDataSetChanged() and hopefully see the same recyclerview as before except with the swiped view replaced with a picture.
Edit:
ooh, you know a better idea would be to forget about the exterior frame and just cover the entire original MyCustomView with an invisible imageView with high elevation. Then inside of the onSwiped() inside of ItemTouchHelper.Callback(), you could just provide the image resource and toggle visibility. That would be way cleaner.
Answered By - D. Kupra
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.