android-recyclerview

How to change the recyclerview first row layout?

纵饮孤独 提交于 2019-12-09 10:23:58
问题 I want to add different layout for the first row, how can i set it up? Adapter class: This is the normal, all row equals: @Override public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { inflater=LayoutInflater.from(parent.getContext()); return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_trends, parent, false)); } And what to change in the OnBindViewHolder method? 回答1: First you need to override getItemViewType . Return itemType according

Recyclerview onscrolllistener not working when setNestedScrollingEnabled to false

谁说胖子不能爱 提交于 2019-12-09 09:25:53
问题 I want to implement pagination with recyclerView , for this I add addOnScrollListener to the recyclerView but I am having trouble with RecyclerView.OnScrollListener not working when I set rvGridExplore.setNestedScrollingEnabled(false); But when I remove rvGridExplore.setNestedScrollingEnabled(false); it is working fine, I don't know how to handle this. Here is code: rvGridExplore = (RecyclerView) view.findViewById(R.id.rvGridExplore); final GridLayoutManager glm = new GridLayoutManager

Get x/y positions of nth item in RecyclerView

僤鯓⒐⒋嵵緔 提交于 2019-12-09 09:17:15
问题 I would like to know how to get the X or Y position of nth item in RecyclerView. This is easy to do if the item is currently within the visible range. However, when the view is currently off the screen (e.g., current visible items range on the RecyclerView is 4 to 7, while the item I am interested in is, say, 1 or 10), there seems to be no way to get that value. Here's what I have tried. I have the following three fields: private RecyclerView rv; /* The Layout Manager of rv */ private

How to disable RecyclerView Items from clicking

笑着哭i 提交于 2019-12-09 09:05:25
问题 I am using Floating Action Button. I want to disable Recyclerview Items from Clicking when i press FAB button. I tried this method but not working setClickable(true); My Layout <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:fab="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:background="#fff"

Expand appbarlayout when recyclerview is scrolled/fling to top

血红的双手。 提交于 2019-12-09 08:56:14
问题 I implemented a collapsingtoolbar layout with a recyclerview as shown in the sample code attached. My issue is that, when I fling the list downward, it does not go all the way to the top. What happens is that, the scrolling stops right at the point where the AppBarLayout is supposed to end. The effect that I want is upon flinging the list downward, the list will go all the way to the top AND reveal/expand the AppBarLayout My minSdk is 14. Any help or suggestion is greatly appreciated. <?xml

Android Recyclerview MediaPlayer previous Item sound stop, release after new one is clicked

…衆ロ難τιáo~ 提交于 2019-12-09 07:04:51
问题 In my app i have recyclerview items, and each item play sound when i click it. Problem is that when i click few items, they all play sounds in the same time until they finish. Lets say i click 10 items, all 10 play sounds in the same time and after some time app get crashed and i get this error: E/MediaPlayer: error (1, -19) . I avoid app crashing by implementing automatic release with this code: mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public

How to add OnClickListner to CardView?

霸气de小男生 提交于 2019-12-09 06:35:23
问题 I am working with RecyclerView and CardView . I want to attach OnClickListner to each card. I tried with many answers available on stackoverflow, but they are not working for me. So far I have tried - public class SubjectAdapter extends RecyclerView.Adapter<SubjectAdapter.ViewHolder> implements View.OnClickListener, View.OnLongClickListener{ private static final String LOGCAT = "SubjectAdapter"; private final Context mContext; List<Subject> SubjectsList; public SubjectAdapter(Context context)

Android Paging library doesn't fire loadAfter()

余生长醉 提交于 2019-12-09 04:33:04
问题 I'm using the new Android Paging library to get a RecyclerView with infinite scrolling. I cannot understand why the library does not fire the loadAfter() method when I setup my PagedList like this: val config: PagedList.Config = PagedList.Config.Builder() .setEnablePlaceholders(false) .setPageSize(10) .setPrefetchDistance(1) .setInitialLoadSizeHint(10) .build() val pageList = PagedList.Builder(LookDataSource(lookList), config) .setInitialKey(0) .setMainThreadExecutor(MainThreadExecutor())

Sorting a Recyclerview

大憨熊 提交于 2019-12-09 02:05:19
问题 Hi guys How would i be able to sort a recyclerview by the data that is within a certain textview which is inside each item inside the recyclerview. I also would love to know how to add a header to each item that is different in the data. ie. Im sorting trying to sort by a date and I want all the dates of xyz to be grouped under one header and the dates of 123 to be grouped under anther geader. Is this possible thanks. Ill post my adapter for now if you need other information just comment

RecyclerView with items of different height: Scrollbar

梦想的初衷 提交于 2019-12-08 23:21:01
问题 I have a RecyclerView with items of varying heights with a scrollbar. Because of the different heights of the items, the scrollbar changes it's vertical size, dependent on which items are currently displayed (see screenshots). I have created an example project that displays the problem here. Has anyone had the same problem and fixed it? How can I override the calculation of the scrollbar height and position to come up with an own implementation? EDIT: The scrollbar's position and height can