嵌套ListView适配器

时间:2015-11-16 22:21:04

标签: android listview android-listview

我正在考虑嵌套ListAdapters,我正在开发一个应用程序,它对图像进行分类并将每个类别放在ListAdapter中,稍后将其放入ListView中,我希望有一些功能,其中每个ListAdapter都有一个水平Listview来显示预览该类别中包含的图像,我使用的是RecyclerView适配器,下面是我的适配器

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



private Context context;
private OnItemClickListener mOnItemClickListener;
private boolean showItems = false;



public CategoryAdapter(OnItemClickListener onItemClickListener)
{
    mOnItemClickListener = onItemClickListener;
}
public interface OnItemClickListener {
    public void onItemClick(View view, int position);
}

@Override
public CategoryAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    context = parent.getContext();
    LayoutInflater inflater = LayoutInflater.from(context);
    View subCat = inflater.inflate(R.layout.open_category_adapter, parent, false);

    // Return a new holder instance
    ViewHolder viewHolder = new ViewHolder(subCat);
    return viewHolder;

}

@Override
public void onBindViewHolder(final CategoryAdapter.ViewHolder holder, final int position) {


    holder.container.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mOnItemClickListener.onItemClick(v, position);
        }
    });


    holder.moreOptions.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //show Existing Items in that SubCategory
            if(showItems == false ) {
                showItems = true;
                holder.moreOptions.setImageResource(R.drawable.ic_menu57b);
            }else
            {
                showItems = false;
                holder.moreOptions.setImageResource(R.drawable.ic_menu57);
            }

        }
    });


     CategoryItem categoryItem = Constant.subCategories.get(position);
    TextView mDescription = holder.mDescription;
    CircularImageView imageView = holder.mImageView;
    mDescription.setText(categoryItem.getmDescription());


    try {

        if(Constant.subCategories.get(position).getmCategoryImgPath() != null ||
                !Constant.subCategories.get(position).getmCategoryImgPath().isEmpty()
                || !Constant.subCategories.get(position).getmCategoryImgPath().equals("")) {



            ResizeImage resize = new ResizeImage();

            BitmapDrawable img = (BitmapDrawable) context.getResources().getDrawable(R.drawable.clothes);

            imageView.setImageBitmap(resize.decodeSampledBitmapFromResource(Constant.subCategories.get(position).getmCategoryImgPath(), 60, 60));


        }else
        {

            ResizeImage resize = new ResizeImage();

            BitmapDrawable img = (BitmapDrawable) context.getResources().getDrawable(R.drawable.clothes);
            imageView.setImageBitmap(resize.decodeSampledBitmapFromResource(context.getResources(), R.drawable.clothes, 60, 60));

            imageView.setImageDrawable(img);
        }


    }catch (Exception e)
    {
        BitmapDrawable img = (BitmapDrawable) context.getResources().getDrawable(R.drawable.clothes);
        imageView.setImageDrawable(img);



    }



}




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




public static class ViewHolder extends RecyclerView.ViewHolder{



        public TextView mDescription;
        public CircularImageView mImageView;
        public View container;
        public ImageButton moreOptions;
        public LinearLayout imageContainer;





    public ViewHolder(View itemView) {

        super(itemView);
            container = itemView;
            mDescription = (TextView) itemView.findViewById(R.id.descriptiontxt);
            mImageView = (CircularImageView) itemView.findViewById(R.id.iimage);
            moreOptions = (ImageButton) itemView.findViewById(R.id.showItems);



              }



}

SubCategory按钮是隐藏和显示水平列表视图,我的问题是我把整个代码混淆了,我似乎无法清楚地了解我将如何更新Horizo​​ntal Listview适配器并删除现有数据如果有人知道我怎么能解决这个问题请咨询。

0 个答案:

没有答案