RecyclerViewは、アダプタを設定していません

コウシクバルガヴァ:

私は、フラグメントで3つのリサイクル景色を眺めることができます。私は彼ら二人のためのアダプタを設定しました。しかし、1つのリサイクルビューは、カードビューを膨張させるが、他にはありません。

私は、コードとショーが呼び出さ取得されていないいないリサイクルビューのアダプタをデバッグしてきました。

これは、フラグメントの私onViewCreated()メソッドであります

public void onViewCreated(View view, @NonNull Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        recyclerViewVendors = view.findViewById(R.id.rcyview_vendors);
        recyclerViewEvents = view.findViewById(R.id.rcyview_home_events);
        String json;
        try{

            InputStream is = getActivity().getAssets().open("vendorServices.json");
            int size = is.available();
            byte[] buffer = new byte[size];
            if(is.read(buffer) == -1){
                throw new EOFException();
            }
            is.close();
            json = new String(buffer, StandardCharsets.UTF_8);

            JSONObject object = new JSONObject(json);
            JSONArray j_Array = object.getJSONArray("vendorServices");

            for(int i=0;i<j_Array.length();i++){
                JSONObject jo_inside = j_Array.getJSONObject(i);
                myDatasetVendors.add(new VendorService(
                        jo_inside.getString("name"),
                        jo_inside.getString("img")
                ));
            }


            is = getActivity().getAssets().open("activities.json");
            size = is.available();
            buffer = new byte[size];
            if (is.read(buffer) == -1) {
                throw new EOFException();
            }

            is.close();
            json = new String(buffer, StandardCharsets.UTF_8);

            JSONObject obj = new JSONObject(json);
            JSONArray m_jArray = obj.getJSONArray("Activities");

            for (int i = 0; i < m_jArray.length(); i++) {
                JSONObject jo_inside = m_jArray.getJSONObject(i);
                myDatasetEvents.add(jo_inside.getString("title"));
            }

        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }



        layoutManagerVendors = new LinearLayoutManager(this.getContext(), LinearLayoutManager.HORIZONTAL, false);
        recyclerViewVendors.setLayoutManager(layoutManagerVendors);

        mAdapterVendors = new AdapterVendorServices(myDatasetVendors, this.getContext());
        recyclerViewVendors.setAdapter(mAdapterVendors);

        layoutManagerEvents = new LinearLayoutManager(this.getContext(), LinearLayoutManager.HORIZONTAL, false);
        recyclerViewEvents.setLayoutManager(layoutManagerEvents);

        mAdapterEvents = new AdapterHomeEvents(myDatasetEvents, this.getContext());
        recyclerViewEvents.setAdapter(mAdapterEvents);
    }


これは呼び出されません私のアダプタです

public class AdapterHomeEvents extends RecyclerView.Adapter<AdapterHomeEvents.MyViewHolder> {
    ArrayList<String> mDataset;
    Context context;

    public AdapterHomeEvents(ArrayList<String> mDataset, Context context) {
        this.mDataset = mDataset;
        this.context = context;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.card_view_home_events, parent, false);
        MyViewHolder vh = new MyViewHolder(v);
        return vh;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.textView.setText(mDataset.get(position));
    }

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

    static class MyViewHolder extends RecyclerView.ViewHolder {
        TextView textView;

        MyViewHolder(View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.txt_crdViewHome_events);
        }
    }
}

私はそれがカードを望む私のリサイクルビューの両方を移入するために期待するが、それは唯一のリサイクルのビューを移入が、それは他に移入されません。

サンディープマリク:

あなたのアダプタにセットサイズに忘れてしまいました: -

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

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=226886&siteId=1