android-recyclerview

The correct way of implementing getItemId() in RecyclerView.Adapter

半腔热情 提交于 2020-06-11 20:06:04
问题 I have generic class public abstract class BaseAdapter<T> extends RecyclerView.Adapter { private List<T> itemsList = new ArrayList<>(); //other override methods @Override public long getItemId(int position) { return position; } } What is the correct way to implementing getItemId()? I think that return position like in many example is not correct. 回答1: Create a base interface that has a method that returns a type long eg. interface BaseInterface{ long getId(); } Change abstract class

RecyclerView - Scroll To Position Not Working Every Time

守給你的承諾、 提交于 2020-06-09 11:47:24
问题 I have implemented a horizontal scrollable RecyclerView . My RecyclerView uses a LinearLayoutManager , and the problem I am facing is that when I try to use scrollToPosition(position) or smoothScrollToPosition(position) or from LinearLayoutManager 's scrollToPositionWithOffset(position) . Neither works for me. Either a scroll call doesn't scroll to the desired location or it doesn't invoke the OnScrollListener . So far I have tried so many different combinations of code that I cannot post

How to access adapter delete button into activity?

时光怂恿深爱的人放手 提交于 2020-06-09 05:32:26
问题 I have a RecyclerView and adapter. Now in that adapter, I'm inflating one row. In that row, there are one delete button and one progressbar. So what I'm doing is when user clicks on delete button, I make invisible that delete button, and make visible small progress bar in place of delete button from Adapter class. And also I'm sending position via listener to that attached activity, from that I'm calling AsyncTask. Now the problem is : When I got to know via AsyncTask that item is deleted, I

Set Margin on RecyclerView programmatically

天大地大妈咪最大 提交于 2020-06-08 07:12:47
问题 I need to set the top margin on a RecyclerView programmatically, but I get this exception: java.lang.RuntimeException: Unable to resume activity java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.support.v7.widget.RecyclerView$LayoutParams Here is my code: RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams)recyclerView.getLayoutParams(); int marginTopDp = (int)getResources().getDimension(R.dimen.margin); int marginTopPx = (int)

“Fold-out” for row in RecyclerView

时光总嘲笑我的痴心妄想 提交于 2020-06-01 05:48:47
问题 Java 8, min SDK: 24, target SDK: 27 My app displays a map with some type of map marker (within a Fragment ) and if I click on one of these markers, a popup comes up to show some additional information about this marker. Currently I'm using a normal AlertDialog for that but I might replace it with a DialogFragment in the future. Inside the dialog there's a RecyclerView that is filled with multiple values. If I click on one of the rows, I want my app to open a "fold-out" underneath it (the

How to run my RecyclerView with CardView in fragment?

久未见 提交于 2020-05-29 11:18:32
问题 I have this code and everytime I tried to run it ..the application is not running not error but not running can anyone please help me to determine what is the reason for getting this kind of problem. because I'm doing RecyclerView with CardView in fragment I have this problem almost a week :( this is my code: public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> { private Context mContext ; private List<Book> mData ; public RecyclerViewAdapter(Context

Is it leak-safe to keep a Context/Activity instance in RecyclerView.Adapter?

末鹿安然 提交于 2020-05-28 14:45:57
问题 Given an adapter like this: public class MyAdapter extends RecyclerView.Adapter { private final Activity mActivity; private final List<Item> mItemList; public MyAdapter(Activity activity, List<Item> itemList) { this.mActivity = activity; this.mItemList = itemList; } //[...] public void onBindViewHolder(ViewHolder holder, int position) { final Item i = mItemList.get(position); holder.launchButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mActivity

Is it leak-safe to keep a Context/Activity instance in RecyclerView.Adapter?

五迷三道 提交于 2020-05-28 14:45:19
问题 Given an adapter like this: public class MyAdapter extends RecyclerView.Adapter { private final Activity mActivity; private final List<Item> mItemList; public MyAdapter(Activity activity, List<Item> itemList) { this.mActivity = activity; this.mItemList = itemList; } //[...] public void onBindViewHolder(ViewHolder holder, int position) { final Item i = mItemList.get(position); holder.launchButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mActivity

How to pass value from recyclerview item to another activity

喜夏-厌秋 提交于 2020-05-27 18:38:14
问题 I'm trying to pass the value in recyclerview item to another activity when we click the recyclerview item. Here I use the OnItemTouchListener . I retrieve data from JSON and parse it into ArrayList. I save 5 parameters. Title, ID, Rating, ReleaseDate, urlPoster, but right now i only show 2 parameters, Title, and image from urlposter. I want to pass the other parameters to another activity, but i can't find out how to do that. There's another question similar like this (Values from

How to pass value from recyclerview item to another activity

ⅰ亾dé卋堺 提交于 2020-05-27 18:35:18
问题 I'm trying to pass the value in recyclerview item to another activity when we click the recyclerview item. Here I use the OnItemTouchListener . I retrieve data from JSON and parse it into ArrayList. I save 5 parameters. Title, ID, Rating, ReleaseDate, urlPoster, but right now i only show 2 parameters, Title, and image from urlposter. I want to pass the other parameters to another activity, but i can't find out how to do that. There's another question similar like this (Values from