android-recyclerview

Android RecyclerView Adapter is giving null on unit testing

[亡魂溺海] 提交于 2019-12-07 03:09:02
问题 I am trying to test RecyclerView with AndroidJunit4, it is my test code: package com.kaushik.myredmart.ui; // all includes @RunWith(AndroidJUnit4.class) public class ProductListActivityTest { @Rule public ActivityTestRule<ProductListActivity> rule = new ActivityTestRule<>(ProductListActivity.class); @Test public void ensureListViewIsPresent() throws Exception { ProductListActivity activity = rule.getActivity(); View viewByIdw = activity.findViewById(R.id.productListView); assertThat(viewByIdw

Add click listener to Generic RecyclerView Adapter

北城以北 提交于 2019-12-07 02:50:51
问题 Edit As It is a genericAdapter not simple one and I know the methods to add click listener. And it is not a good practice to do this in onCreateViewHolder . So that's why I need a better suggestion I have created a Generic Adapter for RecyclerView in android . Now I want some suggestion to improve it. And how could I add clickListener to it. GenericAdapter.java public abstract class GenericAdapter<T> extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private Context context; private

How to make RecyclerView do recycling inside NestedScrollView?

蹲街弑〆低调 提交于 2019-12-07 02:40:52
问题 I tried to put several views, including RecyclerView , into a NestedScrollView . I used setNestedScrollingEnabled(false) and it looked nice for small data sets but started to be laggy for bigger ones. After spending some time on logging the onCreateViewHolder() method I understood that the recycler view creates them all at once as the old ListView . I tried to find reasons of such behavior in RecyclerView docs, but I found it in ScrollView description: You should never use a ScrollView with a

RecyclerView LinearLayoutManager set item count

≯℡__Kan透↙ 提交于 2019-12-07 02:21:31
In GridLayoutManager i am able to set span count and that makes the items inside the view to resize to be able to fit that span count horizontally. I have a LinearLayoutManager and i want to use it the same way, have a fixed number of items visible and resize them to fit. I use both linear and grid on same view and shows items depending of the screen size. I can't seem to find a way to get both layouts showing the same amount of items. UPDATED My previous answer was to use ItemsAdapter to set each items width, from the code design stand point this is not the best solution. Proper way to do

RecyclerView reverse endless scrolling

走远了吗. 提交于 2019-12-07 02:20:05
问题 I'm creating a chat app and I am trying to implement endless scrolling for RecyclerView in a reversed manner, like start from the bottom and scroll up, when top is reached, load more. When the user opens the chat screen, the app gets the last 20 messages and scrolls to the bottom by default. I want to get more messages from the server as the user scrolls up. The following is just a generic endless scrolling code i am testing with: protected void onCreate(Bundle savedInstanceState) { super

Force RecyclerView to call onCreateViewHolder

Deadly 提交于 2019-12-07 01:55:20
问题 I have a RecyclerView that can show items as list, small grids or large grid and this can be change at runtime. Depending on what style user chooses i inflate different layout in onCreateViewHolder . I also use layoutManger.setSpanSizeLookUp() to switch between styles. My code looks like this layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if(showType == ProductAdapter.SHOW_TYPE_SMALL_GRID) return 1; else return

Elevated RecyclerView items get progressively deformed (elevation changes)

老子叫甜甜 提交于 2019-12-07 01:54:18
问题 Any idea why RecyclerView items get deformed , each consecutive item gets worse? UPDATE: I'm using CardViews and now there's no view "deformation" but the shadow/elevation height changes. It seems that elevation gets higher depending on where on the screen the item is located vertically, the shadow grows as the item gets scrolled down. Please see the video here: https://youtu.be/nROYq8rpUMs. I've set up a new project leaving only the code necessary to demonstrate the issue: MainActivity.java

Toolbar not hiding on RecyclerView scroll

只谈情不闲聊 提交于 2019-12-07 00:07:49
问题 I'm trying to make the Toolbar in my app hide and show based on the RecyclerView 's scrolling. This gif shows what I'm trying to achieve. I'm following this tutorial and not getting the results I'm looking for. Here is my activity's layout: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/coordinatorLayout" android:layout_width="match_parent" android:layout_height=

control fling speed for recycler view

Deadly 提交于 2019-12-06 23:58:01
问题 I have a RecyclerView in which i have an image ,a few TextView s and 2 ImageButton s. I have 7-8 such rows to display in my Activity . The scroll is very smooth in android 4.4.4 and below versions but it kind of gives some jerking effect in lollipop. I think that controlling the fling speed for the RecyclerView will do the trick. I searched for it, but found nothing.Instead i found how to take the view to a particular position for the fling. But I want to control the fling speed. Can friction

doesn't show getSupportFragmentManager on ViewHolder in RecyclerView

北慕城南 提交于 2019-12-06 23:19:06
问题 In ViewHolder , I can't call getSupportFragmentManager . I want to change between Fragment I searched all of the google page. but I can't find it. public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ public ImageView imgThumbnail;//img public TextView tvspecies; //text public ViewHolder(View itemView) { super(itemView); imgThumbnail = (ImageView)itemView.findViewById(R.id.img_thumbnail); tvspecies = (TextView)itemView.findViewById(R.id.tv_species);