android-viewholder

How to make RecyclerView stops recycling defined positions?

六月ゝ 毕业季﹏ 提交于 2019-11-29 11:49:27
问题 My problem is: I have a video streaming happening on one of the views inside the RecyclerView. When the user scrolls, the view gets recycled and other cameras starts their own streaming on that recycled viewholder. This is bad for user interface since the streaming process takes some seconds to start. How can I say to the RecyclerView: "Hey Recycler, please, do not recycle that exact position x and give that position ALWAYS the same viewholder you gave it the first time, instead of random one

How open fragment from RecyclerView.Adapter<CardAdapter.ViewHolder>

时光怂恿深爱的人放手 提交于 2019-11-29 11:06:08
问题 1.TabLayout - tab1 (Fragment1) - tab2 (Fragment2) - tab3 (Fragment3) * RecyclerView + CardView (OnClick) On CardView ClickListner open another fragment in tab3. So how to open fragment in tab3. Error is in getFragmentManager() : FragmentTransaction transaction = getFragmentManager().beginTransaction(); Instead of this, I tried: FragmentTransaction transaction = activity.getFragmentManager().beginTransaction(); FragmentTransaction transaction = itemview.getContext().getFragmentManager()

Why does the input value in EditText swaps its position while scrolling in a RecyclerView?

家住魔仙堡 提交于 2019-11-29 09:34:26
问题 After putting an input in the EditText, if a scroll up or down very fast the input values swaps its position in another EditText in a RecyclerView. Before scrolling the data was in the first EditText. After scrolling up and down the value of the first EditText changed its postion to the 4th one and the swapping is random. Is there any work around to steady the data. Here is a sample screenshot Here is the Model Class: public class Product { public int pId; public String pName; public double

Recycler view with volley image request (cancel request)

六眼飞鱼酱① 提交于 2019-11-29 08:52:46
So i am using recycler view to show images in a grid and downloading images from url as bitmaps using volley library. public void onBindViewHolder(final TrendingAdapter.ViewHolder viewHolder, int i) { ImageRequest request = new ImageRequest(url, new Response.Listener<Bitmap>() { @Override public void onResponse(Bitmap bitmap) { if (bitmap != null) { viewHolder.getmImageView().setImageBitmap(bitmap); } } }, 0, 0, null, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { } }); AppController.getInstance().addToRequestQueue(request); } The problem is

Getting position of View in onCreateViewHolder

孤者浪人 提交于 2019-11-29 01:28:16
I am using a RecyclerView with a single row layout with an ImageView and a TextView. I want to implement a OnClickListener for the View and not for seperate ViewHolder objects. How can i get the position of the view in the Adapter? Right now i'm deleting comments on click, but i cannot select the clicked View. I added a TODO in the appropriate line. public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.ViewHolder> { /** List of Comment objects */ private List<Comment> mCommentList; /** Database with Comment objects */ private CommentsDataSource mDataSource; /** * Construcutor

onBindViewHolder() is never called on view at position even though RecyclerView.findViewHolderForAdapterPosition() returns null at that position

限于喜欢 提交于 2019-11-29 00:45:34
问题 I have a list with 13 items (although items may be added or removed), positions 0-12. When the fragment containing the RecyclerView is first shown, only positions 0 through 7 are visible to the user (position 7 being only half visible). In my adapter I Log every time a view holder is binded/bound (idk if grammar applies here) and record its position. Adapter @Override public void onBindViewHolder(final ViewHolder holder, final int position) { Log.d(TAG, "onBindViewHolder() position: " +

RecyclerView Adapter and ViewHolder update dynamically

谁都会走 提交于 2019-11-28 23:43:40
I am trying to make an app that will be loading news from the network and will be updating dynamically. I am using a RecyclerView and CardView to display the content. I use Jsoup to parse sites. I don't think that my code is needed because my question is more theoretical than practical. I want to understand the process of dynamic updating using notifyDataSetChanged() . In my main activity I get all the headers and add them to list. But I need to wait untill all the items are loaded to start displaying them. I would really appreciate if someone could post a sample code of what I'm trying to do

ViewHolder - good practice

懵懂的女人 提交于 2019-11-28 07:44:11
A little newbie question. Why should we initialize the ViewHolder in getView() ? Why can't we initialize it in the constructor? You will have multiple ViewHolder objects in existence. A ListView by its nature doesn't create new View instances for each of its rows. This is so that if you have a ListView of a million things, you don't need to store layout information for a million things. So what do you need to store? Just the things that are on the screen. You can then reuse those views over and over again. This way, your ListView of a million objects can just have maybe 10 child views. In your

Android: RecyclerView content messed up after scrolling [closed]

爱⌒轻易说出口 提交于 2019-11-28 06:20:30
I'm using RecyclerView to display a list of marks, and each mark of the value is shown as a CardView. But some contents of the cards are lost after the scrolling the RecyclerView down and scrolling back, as shown in the two screenshots below. The contents in the red rectangle is lost after scrolling. BEFORE THE SCROLLING; AFTER THE SCROLLING; I'm wondering whether or not it's a bug of RecyclerView and find no solution after Googling for it. All views are invisible except the title, their visibilities are depends on the mark's value. Does anyone know why this would happen? onBindHolder called

What difference between static and non static viewholder in RecyclerView Adapter?

纵然是瞬间 提交于 2019-11-28 03:05:47
What are the advantages of this approach (using static nested class in my class MyAdapter extends RecyclerView.Adapter): static class MyVH extends RecyclerView.ViewHolder {...} And this approach (using member inner class): class MyVH extends RecyclerView.ViewHolder {...} Or it doesn't affect performance and both approaches could be used? droidpl It is more a java question than an Android question. It is recommended to use static for inner classes to avoid memory leaks if you will take their instances out of the class. You can have a look at this awesome post that explains the memory leaks on