如何在回收站视图中显示ArrayList <Hashmap <String,String >>

Vis*_*han 0 android arraylist hashmap recycler-adapter android-recyclerview

我正在实现一个显示相似结果的搜索结果页面。我有一个Hash-Maps的数组列表(具有50个地图,其中每个地图都有12个值)。我想在结果页面的卡片视图中显示每个地图。我尝试为此使用回收站视图。但无法解决这个问题。我已经遍历了堆栈溢出中的所有线程,但找不到任何东西。

ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String,String>>();

nodes = docc.getElementsByTagName("Table");
            int k = nodes.getLength();

            for (int i = 0; i < k; i++) {
                Element e = (Element) nodes.item(i);
                HashMap<String, String> map = new HashMap<String, String>();
                patid = getValue(e, "iPat_id");
                patname = getValue(e, "cPat_Name");
                patAge = getValue(e, "iAge");
                cMaritalSt = getValue(e, "cMarital_St");
                OpRegNo = getValue(e, "iReg_No");
                Doc_Id = getValue(e, "iDoc_id");
                Dept_Id = getValue(e, "iDept_id");
                DocName = getValue(e, "cDocName");
                PatAddress = getValue(e, "PatAddress");
                mobileno = getValue(e, "cMobile");
                patdob = getValue(e, "dDob");
                iOP_Reg_No = getValue(e, "iOP_Reg_No");

                map.put("iPat_id", patid);
                map.put("cPat_Name", patname);
                map.put("iAge", patAge);
                map.put("cMarital_St", cMaritalSt);
                map.put("iReg_No", OpRegNo);
                map.put("iDoc_id", Doc_Id);
                map.put("iDept_id", Dept_Id);
                map.put("cDocName", DocName);
                map.put("PatAddress", PatAddress);
                map.put("cMobile", mobileno);
                map.put("dDob", patdob);
                map.put("iOP_Reg_No", iOP_Reg_No);
                mylist.add(map);

            }
Run Code Online (Sandbox Code Playgroud)

这是我得到的ArrayList。请给我一个有关如何为此Arraylist设置回收站适配器的示例。

小智 6

下面的代码可能会帮助您。以下是将数据显示到的适配器 RecyclerView

public class TestAdapter extends RecyclerView.Adapter<TestAdapter.ViewHolder> {
        private ArrayList<HashMap> aryList;
        private Context context;

        public TestAdapter(Context context, ArrayList<HashMap> aryList) {
            this.context = context;
            this.aryList = aryList;
        }

        @Override
        public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
            View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.layout_product, viewGroup, false);
            return new ViewHolder(view);
        }

        @Override
        public void onBindViewHolder(ViewHolder viewHolder, int position) {

            viewHolder.setIsRecyclable(false);
                viewHolder.tv_iPat_id.setText(aryList.get(position).get("iPat_id").toString());

        }

        @Override
        public int getItemCount() {
            return aryList.size();
        }

        public class ViewHolder extends RecyclerView.ViewHolder {

            public TextView tv_iPat_id;
             public ViewHolder(View view) {
                super(view);

                            tv_iPat_id = (TextView) view.findViewById(R.id.tv_iPat_id);

            }
        }
Run Code Online (Sandbox Code Playgroud)

要将适配器设置为RecyclerView

TestAdapter testAdapter = new TestAdapter(getActivity(), testList);
        RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity().getApplicationContext());
       rvTest.setLayoutManager(mLayoutManager);
        rvTest.setItemAnimator(new DefaultItemAnimator());
        rvTest.setAdapter(testAdapter);
Run Code Online (Sandbox Code Playgroud)