Posts

Showing posts with the label android-recyclerview

Items in RecyclerView in a Fragmnet don't appear

Image
Items in RecyclerView in a Fragmnet don't appear I saw there are similar post but my code is the same as the codes in the solutions so they weren't useful in my case. My app starts but and two tabs are shown. However the one that is supposed to show the items from a RecyclerView that's in it is empty.I also get this error: E/RecyclerView: No adapter attached; skipping layout So I have an Activity with a TabLayout and a ViewPager public class MainActivity extends AppCompatActivity { TabLayout tabLayout; ViewPager viewPager; PagerAdapter pagerAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tabLayout=findViewById(R.id.tab_layout); viewPager=findViewById(R.id.view_pager); tabLayout.addTab(tabLayout.newTab().setText("CitiesFragment")); tabLayout.addTab(tabLayout.newTab().setText("My CitiesFragme...

RecyclerView: Inconsistency detected. Invalid item position. Cause -Removing item using timer

RecyclerView: Inconsistency detected. Invalid item position. Cause -Removing item using timer Before moving ahead i search about this bug on google and i found the so many answer which are available but my scenario is different than their situation. java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 2(offset:2).state:3 I am using recyclerview to display the poll questions and every question has a timer, Item will removed from the list when timer runs out. Exception is occurring when the timer runs out but in only some rare scenario when less time (for ex 100ms) is remaining. so in that case may be recyclerview is inflating item and at that same time, timer rans out and recyclerview try to remove that item. Bug is when timer removing item i am getting the exception. So I solved it after removing the elements from data set when 1 or less seconds is remaining for that poll. So it will not add item in list and that will run the timer. If you want to produce...

LinearLayoutManager.findLastVisibleItemPosition() returns false position

LinearLayoutManager.findLastVisibleItemPosition() returns false position I am using the following method to implement lazy loading for pagination in RecyclerView : RecyclerView recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); totalItemCount = linearLayoutManager.getItemCount(); lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition(); // starts with 0 if (!mIsLoading && totalItemCount <= (lastVisibleItem + visibleThreshold)) { if (mOnLoadMoreListener != null) { mOnLoadMoreListener.onLoadMore(); } mIsLoading = true; } } }); It works fine on API levels > 22 . However, on APIs 22 and below, the onScrolled() is called multiple times by itself until all the pages are loade...

LayoutManager for RecycleView for what?

LayoutManager for RecycleView for what? I can not find an explanations why we need to set LayoutManager for RecycleView . Someone can explain ? LayoutManager RecycleView mLayoutManager = new LinearLayoutManager(this); mRecyclerView.setLayoutManager(mLayoutManager); Actually have you read about LayoutManager? if no please read here – Sree... Jun 29 at 10:52 Please read about Layout manager over here – Wizard Jun 29 at 10:52 developer.android.com/reference/android/support/v7/widget/… – Nilesh Rathod Jun 29 at 10:53 4 An...

Swipe to delete Recyclerview brings about a null object reference error [duplicate]

Swipe to delete Recyclerview brings about a null object reference error [duplicate] This question already has an answer here: I am working with a recyclerview and am implementing swipe to delete. the code works pretty well but when I try getting my list from the adapter so that I implement swipe to delete, I get a null object reference. My adapter class is below public class TlAdapter extends RecyclerView.Adapter<TimelineVholder> { private List<FetchModel> models; private Context context; public TlAdapter(List<FetchModel> models,Context context) { this.models = models; this.context= context; } @NonNull @Override public TimelineVholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View view= LayoutInflater.from(context).inflate(R.layout.timeline,parent,false); return new TimelineVholder(view,viewType); } @Override public void onBindViewHolder(@NonNull TimelineVholder holder, final int position) { SharedPreferences preferences= Prefere...

Grey out recyclerview items which the user has clicked

Grey out recyclerview items which the user has clicked Working on an app where news get displayed in recyclerview. I want to add a functionality where when the user clicks on one of the recyclerview items (which opens the news in a new activity) the item gets greyed out (or something that indicates that the user has opened said news). My idea was to get the news ID the user clicked on and add it to sharedpreferences file. With that I could create a simple check and grey out news where the ID equals to the one in the SharedPreferences file. I feel like that isn't the best way to do it but I can't think of any other way. Any feedback is much appreciated! :) clicks recyclerview items greyed out SharedPreferences Recyclerview <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/mainTextBGColor" andr...