我正在开发电子商务应用。我想设计类似于Flipkart应用程序的主页。我使用了回收站视图。我能够成功显示数据但我想要的是显示列表中的前10个元素,即1行,即1到10.在2行中,项目应该是从11日到20日。
现在它在所有行中显示1到15个项目,因为我的列表大小为15。
public class RecyclerViewAdapter3 extends RecyclerView.Adapter<RecyclerViewAdapter3.RecyclerViewHolders> {
//private List<ItemObject> itemList;
private List<String> itemList2;
private Context context;
private static final int ITEM_VIEW_TYPE_HEADER = 0;
private static final int ITEM_VIEW_TYPE_ITEM = 1;
private View header;
private GridLayoutManager lLayout;
public RecyclerViewAdapter3(Context context) {
// this.itemList = itemList;
// this.itemList2=itemList2;
this.context = context;
}
@Override
public RecyclerViewHolders onCreateViewHolder(ViewGroup parent, int viewType) {
Log.i("pos on create holder",""+viewType);
/* if (viewType == ITEM_VIEW_TYPE_HEADER) {
return new RecyclerViewHolders(header);
}else {*/
View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_view, null);
RecyclerViewHolders rcv = new RecyclerViewHolders(layoutView);
return rcv;
// }
}
@Override
public void onBindViewHolder(RecyclerViewHolders holder, int position) {
List<ItemObject> rowListItem = getAllItemList();
/* LinearLayoutManager layoutManager = new LinearLayoutManager(context);
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);*/
//layoutManager.scrollToPosition(currPos);
lLayout = new GridLayoutManager(context, 1, GridLayoutManager.HORIZONTAL, false);
// lLayout = new GridLayoutManager(context, 10);
int spacingInPixels = context.getResources().getDimensionPixelSize(R.dimen.spacing);
// holder.rView.addItemDecoration(new SpacesItemDecoration(spacingInPixels));
// lLayout.setFullSpan(true);
holder.rView.setHasFixedSize(true);
holder.rView.setLayoutManager(lLayout);
final RecyclerViewAdapter rcAdapter = new RecyclerViewAdapter(context, rowListItem);
holder.rView.setAdapter(rcAdapter);
}
@Override
public int getItemCount() {
return 5;
}
public class RecyclerViewHolders extends RecyclerView.ViewHolder{
public RecyclerView rView;
public RecyclerViewHolders(View itemView) {
super(itemView);
rView = (RecyclerView) itemView.findViewById(R.id.recycler_view);
}
}
private List<ItemObject> getAllItemList(){
List<ItemObject> allItems = new ArrayList<ItemObject>();
allItems.add(new ItemObject("United States", R.drawable.ic_launcher));
allItems.add(new ItemObject("Canada", R.drawable.ic_launcher));
allItems.add(new ItemObject("United Kingdom", R.drawable.ic_launcher));
allItems.add(new ItemObject("Germany", R.drawable.ic_launcher));
allItems.add(new ItemObject("Sweden", R.drawable.ic_launcher));
allItems.add(new ItemObject("United Kingdom", R.drawable.ic_launcher));
allItems.add(new ItemObject("Germany", R.drawable.ic_launcher));
allItems.add(new ItemObject("Sweden", R.drawable.ic_launcher));
allItems.add(new ItemObject("United States", R.drawable.ic_launcher));
allItems.add(new ItemObject("Canada", R.drawable.ic_launcher));
allItems.add(new ItemObject("United Kingdom", R.drawable.ic_launcher));
return allItems;
}
}