recycler-adapter

Create RecyclerView item layout based on content of data

荒凉一梦 提交于 2019-12-06 06:38:02
I'm creating a recycler view of data objects, each of these object will vary, eg. Obj 1 - String Heading - String Desc - Image Obj 2 - String Desc Obj 3 - Image - String Link Obj 4 - String Desc - Video etc So I need to create my item layout dynamically to suit each data object. I don't want to create an item layout with all the possible views and components and show and hide as I feel it's bad practice. So my issue is I need to access an object from the list using the position in the onBindViewHolder in order to construct my layout in the ViewHolder class. I tried using a method which I

Update text within card view list?

江枫思渺然 提交于 2019-12-06 04:21:32
So I have a recyclerview list of card views.I am trying to update the text time text in each view when the user clicks the card, and then reset it back when time has past. I set up an internal method in recyclerviewadapter but when I call updateTimes (calling from fragment), it does not reset the text back. Can someone instruct me on what I'm doing wrong? import java.util.ArrayList; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.net.Uri; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content

java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false isAttached:true when scrolling down

放肆的年华 提交于 2019-12-05 22:54:08
FATAL EXCEPTION: main Process: com.zipato.android.client.v2, PID: 24966 java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false isAttached:true at android.support.v7.widget.RecyclerView$Recycler.recycleViewHolderInternal(RecyclerView.java:5736) at android.support.v7.widget.RecyclerView$Recycler.recycleView(RecyclerView.java:5680) at android.support.v7.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:289) at android.support.v7.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:336) at android.support.v7.widget.GapWorker

How to properly use LiveData with RecycleView

青春壹個敷衍的年華 提交于 2019-12-05 18:35:33
I have a project that loads a list from the server. This data will eventually be stored into a database, but for now is stored in memory in a MutableLiveData. A RecyclerView's adapter is watching the data and displaying it. So far everything is working as expected, using a FAB the user can post a new entry which will go at the top of the list, on success I get a 200 and here's the main part where I'm getting lost... When I want to add a single item to a list stored in a LiveData, the observer is unaware of the delta. I currently make a call to RecyclerView.Adapter.notifyDataSetChanged() ,

Countdown timer in recyclerview not working properly

廉价感情. 提交于 2019-12-05 18:25:27
I have created a recyclerview that contains multiple data and a countdown timer too . All the things working properly untill i couldn't scroll the list . when i scroll down the list countdowntimer will conflicts with the above view items . It counts the current view time and the random time also . I tried too many things to solved it but couldn't able to . Please help me out . Thanks in advance . Here is my RecyclerAdapter's code . public class ReferendumQuestionAdapter extends RecyclerView.Adapter<ReferendumQuestionAdapter.MyViewHolder> { List<QuestionsModel.QuestionsData> questionBeen = new

Recycler View Fatal Exception: java.lang.ArrayIndexOutOfBoundsException

℡╲_俬逩灬. 提交于 2019-12-05 18:20:33
问题 I have got this stack trace though crashlytics. I have no idea where the issue is. Is there any alternative of StaggeredGridLayoutManager that I can use to get a listview like layout. Fatal Exception: java.lang.ArrayIndexOutOfBoundsException: start < 0 || end > len. start=-1, end=11, len=11 at java.util.Arrays.checkStartAndEnd(Arrays.java:1745) at java.util.Arrays.fill(Arrays.java:803) at android.support.v7.widget.StaggeredGridLayoutManager$LazySpanLookup.invalidateAfter(SourceFile:2404) at

java.lang.IllegalStateException: TextView must not be null (Android/Kotlin)

烈酒焚心 提交于 2019-12-05 14:38:25
问题 I have the following ViewHolder class for my Recycler View, inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { private val dateText = itemView.itemDateSummaryList private val systolicVal = itemView.systolicValue private val diastolicVal = itemView.diastolicValue fun update(listItem: SummaryListItemModel) { Log.i(TAG, "Update method called " + listItem.date) dateText.text = listItem.date systolicVal.text = listItem.sysVal.toInt().toString() diastolicVal.text =

How to create auto adjust grid layout using android RecyclerView

杀马特。学长 韩版系。学妹 提交于 2019-12-05 07:21:38
问题 I want to create auto adjust columns like above image Grid Layout using RecyclerView. 回答1: At last, I have done it using FlexboxLayout ///Gradle import/// compile 'com.google.android:flexbox:0.3.1' public class MainActivity extends AppCompatActivity { List<String> list_text=new ArrayList<>(); FlexboxLayout container; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); container=findViewById(R.id.v_container

Android Support Repository 23.2.1 RecyclerView error [duplicate]

旧城冷巷雨未停 提交于 2019-12-04 19:30:33
This question already has answers here : RecyclerView items with big empty space after 23.2.0 (4 answers) Closed 3 years ago . After update my support libraries 23.2.1, I encountered a problem. Even I didn't change any code only library update, my recyclerview item's become not shown. Only first item shown, others not shown. I have no idea why it is not show all elements. Is there anybody encounters this problem and how to fix it? Before library update After library update Note: Unfortunaley I couldn't change my IDE Eclipse to Android Studio. There was a change in the support library 23.2.1

Pagination while scrolling recycler view to the top

China☆狼群 提交于 2019-12-04 13:29:33
I have a requirement for implementing pagination while scrolling up a RecyclerView. I am facing some issues as while adding content to the 0th position and notifying the adapter, recyclerview automatically scrolls to the top. Is there a way to disable that behaviour? @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { setFields(viewHolder, data); if (position == 0 && getParentFragment().hasPrevious()) { getParentFragment().callPreviousPage(); } } Where setFields(viewHolder, data); method sets values to different fields. if (position == 0 && getParentFragment(