Tôi muốn rằng chuỗi khóa phải hoạt động như tiêu đề và danh sách phải được thổi phồng dưới khóa bản đồ đó trong RecyclerView
.Làm thế nào để phồng băm Hashmap <String, List <Items>> vào Recyclerview
nhờ sự giúp đỡ nào
public class Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
private WeakHashMap<String, List<VideoItem>> mData = new WeakHashMap<>();
private ArrayList<String> mKeys;
ArrayList<WeakHashMap<String,List<VideoItem>>> hashMapArrayList;
public Adapter(WeakHashMap<String, List<VideoItem>> mData, ArrayList<WeakHashMap<String,List<VideoItem>>> hashMapArrayList) {
this.mData = mData;
this.hashMapArrayList=hashMapArrayList;
mKeys = new ArrayList<String>(mData.keySet());
}
public String getKey(int position)
{
return (String) mKeys.get(position);
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.player_item, parent, false);
MyViewHolder holder=new MyViewHolder(v);
return holder;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
String key = getKey(position);
WeakHashMap<String, List<VideoItem>> value = hashMapArrayList.get(position);
MyViewHolder holder1=(MyViewHolder)holder;
holder1.header.setText(key);
holder1.value.setText(value.get(key).get(position).getDuration());
Log.v("KEY",key);
Log.v("VALUE", String.valueOf(value));
}
@Override
public int getItemCount() {
return (null != hashMapArrayList ? hashMapArrayList.size() : 0);
}
// public ArrayList<WeakHashMap<String,List<VideoItem>>> getItem(int position) {
// return hashMapArrayList.get(mKeys.get(position));
// }
@Override
public long getItemId(int position) {
return position;
}
class MyViewHolder extends RecyclerView.ViewHolder{
TextView header ;
TextView value;
public MyViewHolder(View itemView) {
super(itemView);
header= (TextView) itemView.findViewById(R.id.header);
value= (TextView) itemView.findViewById(R.id.task_name);
}
}
}
đăng mã bộ điều hợp của bạn, chúng tôi sẽ trợ giúp từ đó – inkedTechie
thử sử dụng: https://github.com/timehop/sticky-headers-recyclerview –
tôi muốn tạo các phần trong recyclerview bằng cách sử dụng khóa làm phần và giá trị danh sách theo những phần –