带有部分的RecyclerView仅显示显示的项目

时间:2016-12-09 08:09:01

标签: android android-recyclerview

我的RecyclerView with section显示所有两个部分只显示6个项目,但我的设备ArrayList中还有更多项目。

回收商布局的高度已经为wrap_content

这是我的LinearRecyclerAdapter以及章节:

public class LinearRecyclerAdapter extends RecyclerView.Adapter<LinearRecyclerAdapter.ViewHolder> {

ArrayList<Category> mCategory = new ArrayList<>();
ArrayList<Category> mCopyCategory = new ArrayList<>();
String tablequery = null;
Activity mActivity;
GridRecyclerAdapter mAdapterGrid;

public LinearRecyclerAdapter(Activity activity, ArrayList<Category> category, String table) {
    mActivity = activity;
    mCategory = category;
    tablequery = table;
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.catrecyclerlayout, parent, false);
    ViewHolder viewHolder = new ViewHolder(v);
    mCopyCategory.clear();
    mCopyCategory.addAll(mCategory);
    return viewHolder;
}

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
    holder.position = position;
    holder.category = getCategory(position);
    holder.device_array = getDevices(position);
    holder.isInt = getBool(position);

    if (position != 0)
        holder.tv_category.setText(holder.category);
    else
        holder.mLinearLayout.setVisibility(View.GONE);

    mAdapterGrid = new GridRecyclerAdapter(mActivity, holder.device_array, tablequery, holder.isInt);
    holder.recyclerView.setAdapter(mAdapterGrid);

    holder.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            mAdapterGrid.notifyDataSetChanged();
        }
    });
}

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

public String getCategory(int position) {
    return mCategory.get(position).getmCategory();
}

public ArrayList<Devices> getDevices(int position) {
    return mCategory.get(position).getmDevices();
}

public boolean getBool(int position) {
    return mCategory.get(position).getisInt();
}

class ViewHolder extends RecyclerView.ViewHolder {

    public int position;
    public String category;
    public ArrayList<Devices> device_array;
    public boolean isInt = false;

    public TextView tv_category = null;
    public RecyclerView recyclerView = null;
    public RecyclerView.LayoutManager mLayoutManager = null;
    public LinearLayout mLinearLayout = null;
    public View mView;

    public ViewHolder(View itemView) {
        super(itemView);
        mView = itemView;
        mLinearLayout = (LinearLayout) itemView.findViewById(R.id.category_ll);
        recyclerView = (RecyclerView) itemView.findViewById(R.id.recycler_view);
        tv_category = (TextView) itemView.findViewById(R.id.tv_category);

        // Calling the RecyclerView
        recyclerView.setHasFixedSize(true);

        // The number of Columns
        mLayoutManager = new GridLayoutManager(mActivity, 2);
        recyclerView.setLayoutManager(mLayoutManager);
        recyclerView.setNestedScrollingEnabled(false);
    }
}
}

这是一个屏幕截图,向您展示我的意思

我希望有人可以帮助我,我尝试了我所知道的一切:(

Shows 6 items by all two sections

1 个答案:

答案 0 :(得分:0)

解决了我的问题

我忘记了一个relativelayout将高度设置为wrap_content -.-