您好我正在尝试为recycleler-view添加页脚视图,我使用下面的代码来执行我的要求,但是当我调试我的代码时,我得到例外:
二进制XML文件行#12:
二进制XML文件行#12:错误导致类06-08 13:22:35.232 5905-5905 /? W / System.err:引起: android.view.InflateException:二进制XML文件行#12:错误 膨胀班 引起:java.lang.reflect.InvocationTargetException
-
public class HorizentalAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context context;
private ArrayList<File> fileArrayList;
private static final int TYPE_ITEM = 1;
private static final int TYPE_FOOTER = 2;
public HorizentalAdapter(Context context, ArrayList<File> fileArrayList) {
this.context = context;
this.fileArrayList = fileArrayList;
}
/**
* @param parent
* @param viewType
* @return
*/
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
try {
if (viewType == TYPE_FOOTER) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_footer_layout,
parent, false);
return new FooterViewHolder(v);
} else {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_horizental_layout,
parent, false);
return new ViewHolder(v);
}
} catch (Throwable throwable) {
throwable.printStackTrace();
}
return null;
}
/**
*
* @param holder
* @param position
*/
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
try {
if (holder instanceof AuditAdapter.ViewHolder) {
ViewHolder headerHolder = (ViewHolder) holder;
Bitmap myBitmap = BitmapFactory.decodeFile(String.valueOf(fileArrayList.get(position)));
headerHolder.imageView.setImageBitmap(myBitmap);
} else {
FooterViewHolder footerViewHolder = (FooterViewHolder) holder;
}
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
@Override
public int getItemCount() {
try{
return fileArrayList.size() + 1;
}catch (Throwable throwable){
throwable.printStackTrace();
}
return 0;
}
/**
* getItemViewType
*
* @param position
* @return
*/
@Override
public int getItemViewType(int position) {
if (position == fileArrayList.size() + 1) {
return TYPE_FOOTER;
}
return TYPE_ITEM;
}
/**
* View holder to display each RecylerView item
*/
protected class ViewHolder extends RecyclerView.ViewHolder {
private CircleImageView imageView;
public ViewHolder(View view) {
super(view);
imageView = view.findViewById(R.id.grid_image);
}
}
/**
* FooterViewHolder
*/
protected class FooterViewHolder extends RecyclerView.ViewHolder {
public FooterViewHolder(View view) {
super(view);
}
}
}