android-viewholder

Dynamically adding Views in a RecyclerView only to current item

人走茶凉 提交于 2019-11-30 09:10:05
问题 I'm dynamically adding Views to my items in a RecyclerView . These added Views should only be related to the item which they're added to, but I'm having a problem when I scroll. It seems the View is recycled and a new item is loaded, but those previously added views are still there, only now on the wrong item. I'm assuming that it's just because the ViewHolder is being reused, so the added items show up again with a new item, when loaded. How would one go about solving this? 回答1: This was an

How to make RecyclerView stops recycling defined positions?

狂风中的少年 提交于 2019-11-30 08:12:17
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"? Please someone help me =( In your getItemViewType(int position) method of adapter, assign unique

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

断了今生、忘了曾经 提交于 2019-11-30 08:10:10
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().beginTransaction(); But error is not resolve. Here is my code: public class CardAdapter extends RecyclerView

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

穿精又带淫゛_ 提交于 2019-11-30 07:24:06
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 unit_price; public double discount; } Here is the adapter Class: public class ProductAdapter extends

Getting position of View in onCreateViewHolder

瘦欲@ 提交于 2019-11-30 07:10:30
问题 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>

How to call a MainActivity method from ViewHolder in RecyclerView.Adapter?

前提是你 提交于 2019-11-30 06:56:52
In a simple app project at GitHub I have only 2 custom Java-files: MainActivity.java contains Bluetooth- and UI-related source code DeviceListAdapter.java contains an Adapter and ViewHolder for displaying Bluetooth devices in a RecyclerView The MainActivity.java contains a method to be called, when user taps on a Bluetooth device in the RecyclerView : public void confirmConnection(String address) { final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Do you want to pair to " + device + "?");

RecyclerView Recycled ViewHolder Image View wrong size

纵饮孤独 提交于 2019-11-30 04:55:19
问题 I have a recycler view with different View Holders. A couple of view holders have image views which I pass into Glide to display images. The problem is, when the recycler view starts recycling views, the imageview width/height are that of the recycled view they then display the image incorrectly. Here is my ImageView: <ImageView android:id="@+id/image" android:layout_marginTop="@dimen/feed_item_margin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout

Android: how can I insert a RecyclerView inside CardView?

坚强是说给别人听的谎言 提交于 2019-11-30 02:01:08
The activity I am talking about must show a RecyclerView populated by CardViews as items. My goal is to show in every CardView a RecyclerView in its turn. Here my Activity's basic xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".ConjActivity" > <android.support.v7.widget.RecyclerView android:id="@+id/conjCardList" android:layout_width="match_parent" android:layout_height="match_parent" android

Implement multiple ViewHolder types in RecycleView adapter

给你一囗甜甜゛ 提交于 2019-11-30 01:32:26
It's maybe a discussion not a question. Normal way to implement multiple types As you know, if we want to implement multiple types in RecyclerView , we should provide multiple CustomViewHolder extending RecyclerView.ViewHolder . For exmpale, class TextViewHolder extends RecyclerView.ViewHolder{ TextView textView; } class ImageViewHolder extends RecyclerView.ViewHolder{ ImageView imageView; } Then we have to override getItemViewType .And in onCreateViewHolder to construct TextViewHolder or ImageViewHolder . @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int

RecyclerView - callback when view is no longer visible

不想你离开。 提交于 2019-11-29 23:59:36
I have a RecyclerView with its Adapter and LayoutManager. Adapter has approximate 15 different ViewHolders. One of them contain WebView which loads external contents (99% of them are videos outside of YouTube). The problem comes when any View of Adapter gets out of the screen - video in WebView keeps playing and sound is playing. Still, that's acceptable for me. The key problem starts when I move to another Activity. The sound of the video is still present. Is there any way RecyclerView could notify me when any of its children views change visibility state (meaning disappears from display)?