Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 具有多个项目布局的ListView适配器不工作_Java_Android_Firebase_Android Studio_Google Cloud Firestore - Fatal编程技术网

Java 具有多个项目布局的ListView适配器不工作

Java 具有多个项目布局的ListView适配器不工作,java,android,firebase,android-studio,google-cloud-firestore,Java,Android,Firebase,Android Studio,Google Cloud Firestore,我正在尝试显示一些具有不同布局的文档和图像的列表视图。 它对文档有效,但图像仍然无法显示。 我使用了.contains方法来检查项目是doc还是image。帮我做这个 @Override public View getView(final int position, View convertView, ViewGroup parent) { LayoutInflater layoutInflater = activity.getLayoutInflater(); String f

我正在尝试显示一些具有不同布局的文档和图像的列表视图。 它对文档有效,但图像仍然无法显示。 我使用了.contains方法来检查项目是doc还是image。帮我做这个

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    LayoutInflater layoutInflater = activity.getLayoutInflater();
    String fileName = uriList.get(position).getFileName();

    return viewSetup(position, layoutInflater, fileName);
}

private View viewSetup(final int position, LayoutInflater layoutInflater, String fileName) {
    if (fileName.contains(".png") || fileName.contains(".jpg") || fileName.contains(".jpeg")) {
        View inflate = layoutInflater.inflate(R.layout.main_list_item_img, null, false);
        ImageView imageView = inflate.findViewById(R.id.imgPrev);
        Glide.with(activity).load(uriList.get(position).getDownloadLink()).into(imageView);
        itemSetup(position, fileName, inflate);
        return inflate;

    } else {
        View inflate = layoutInflater.inflate(R.layout.main_list_item_docs, null, false);
        itemSetup(position, fileName, inflate);
        return inflate;

    }
}

private void itemSetup(final int position, String fileName, View inflate) {
    TextView title = inflate.findViewById(R.id.uriTitle);
    TextView desc = inflate.findViewById(R.id.uriDesc);
    ImageView download = inflate.findViewById(R.id.download);
    TextView createdOn = inflate.findViewById(R.id.createdOn);
    title.setText(fileName + "");
    desc.setText(uriList.get(position).getDescription());
    createdOn.setText(uriList.get(position).getSendTime());
    download.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            savefile(uriList.get(position).getDownloadLink());
        }
    });
}

我认为你的图像加载有问题。你可以用毕加索

  Picasso.with(activity).load(yourUrl).
                        placeholder(R.drawable.image_loader).into(myImage);

我认为你的图像加载有问题。你可以用毕加索

  Picasso.with(activity).load(yourUrl).
                        placeholder(R.drawable.image_loader).into(myImage);

您需要使用类型变量,您可以检查我在以下示例中的操作:-

public class JobsAdapter extends BaseAdapter {

private Activity context;
private LinkedList<KeyValuesPair> listItemArrayList;
private LinkedList<Integer> type;
private LayoutInflater inflater;

public JobsAdapter(Activity context, LinkedList<KeyValuesPair> objects, LinkedList<Integer> type) {
    this.context = context;
    this.listItemArrayList = objects;
    this.type = type;
    inflater = LayoutInflater.from(context);
}

@Override
public int getCount() {
    return type.size();
}

@Override
public Object getItem(int position) {
    return position;
}


@Override
public long getItemId(int position) {
    return position;
}

@Override
public boolean isEnabled(int position) {
    return type.get(position) != 0;
}

@TargetApi(Build.VERSION_CODES.O)
public View getView(int position, View convertView, ViewGroup parent) {
    // used new view instead of convertView so the spinner could support multiple views
    View view = null;
    // if type is equals to 0 it will load jobs header else jobs child
    if (type.get(position) == 0) {
        view = inflater.inflate(R.layout.lv_header, null, false);
        TextView header = view.findViewById(R.id.jobsHeading);
        header.setText(listItemArrayList.get(position).getValue());
        if (position == 0) {
            header.setTextSize(16);
            header.setTypeface(context.getResources().getFont(R.font.raleway_regular));
            header.setTextColor(context.getResources().getColor(R.color.colorPrimaryDark));
        } else {
            header.setTextColor(context.getResources().getColor(R.color.colorBlack));
        }
    } else if (type.get(position) == 1) {
        view = inflater.inflate(R.layout.lv_child, null, false);
        TextView child = view.findViewById(R.id.jobsChild);
        child.setText(listItemArrayList.get(position).getValue());
    }
    return view;
}
公共类JobsAdapter扩展BaseAdapter{
私人活动语境;
私有LinkedList listItemArrayList;
私有链接列表类型;
私人充气机;
public JobsAdapter(活动上下文、LinkedList对象、LinkedList类型){
this.context=上下文;
this.listItemArrayList=对象;
this.type=type;
充气器=充气器。从(上下文);
}
@凌驾
public int getCount(){
返回类型.size();
}
@凌驾
公共对象getItem(int位置){
返回位置;
}
@凌驾
公共长getItemId(int位置){
返回位置;
}
@凌驾
公共布尔值isEnabled(整型位置){
返回类型。获取(位置)!=0;
}
@TargetApi(Build.VERSION\u code.O)
公共视图getView(int位置、视图转换视图、视图组父视图){
//使用了新视图而不是convertView,因此微调器可以支持多个视图
视图=空;
//如果type等于0,它将加载作业头else jobs child
if(type.get(position)==0){
视图=充气机。充气(R.layout.lv_标题,空,假);
TextView header=view.findviewbyd(R.id.jobsheding);
header.setText(listItemArrayList.get(position.getValue());
如果(位置==0){
头.setTextSize(16);
header.setTypeface(context.getResources().getFont(R.font.ralway_regular));
header.setTextColor(context.getResources().getColor(R.color.colorPrimaryDark));
}否则{
header.setTextColor(context.getResources().getColor(R.color.colorBlack));
}
}else if(type.get(position)==1){
视图=充气机。充气(R.layout.lv_child,null,false);
TextView-child=view.findviewbyd(R.id.jobsChild);
setText(listItemArrayList.get(position.getValue());
}
返回视图;
}

}

您需要使用类型变量,您可以检查我在以下示例中的操作:-

public class JobsAdapter extends BaseAdapter {

private Activity context;
private LinkedList<KeyValuesPair> listItemArrayList;
private LinkedList<Integer> type;
private LayoutInflater inflater;

public JobsAdapter(Activity context, LinkedList<KeyValuesPair> objects, LinkedList<Integer> type) {
    this.context = context;
    this.listItemArrayList = objects;
    this.type = type;
    inflater = LayoutInflater.from(context);
}

@Override
public int getCount() {
    return type.size();
}

@Override
public Object getItem(int position) {
    return position;
}


@Override
public long getItemId(int position) {
    return position;
}

@Override
public boolean isEnabled(int position) {
    return type.get(position) != 0;
}

@TargetApi(Build.VERSION_CODES.O)
public View getView(int position, View convertView, ViewGroup parent) {
    // used new view instead of convertView so the spinner could support multiple views
    View view = null;
    // if type is equals to 0 it will load jobs header else jobs child
    if (type.get(position) == 0) {
        view = inflater.inflate(R.layout.lv_header, null, false);
        TextView header = view.findViewById(R.id.jobsHeading);
        header.setText(listItemArrayList.get(position).getValue());
        if (position == 0) {
            header.setTextSize(16);
            header.setTypeface(context.getResources().getFont(R.font.raleway_regular));
            header.setTextColor(context.getResources().getColor(R.color.colorPrimaryDark));
        } else {
            header.setTextColor(context.getResources().getColor(R.color.colorBlack));
        }
    } else if (type.get(position) == 1) {
        view = inflater.inflate(R.layout.lv_child, null, false);
        TextView child = view.findViewById(R.id.jobsChild);
        child.setText(listItemArrayList.get(position).getValue());
    }
    return view;
}
公共类JobsAdapter扩展BaseAdapter{
私人活动语境;
私有LinkedList listItemArrayList;
私有链接列表类型;
私人充气机;
public JobsAdapter(活动上下文、LinkedList对象、LinkedList类型){
this.context=上下文;
this.listItemArrayList=对象;
this.type=type;
充气器=充气器。从(上下文);
}
@凌驾
public int getCount(){
返回类型.size();
}
@凌驾
公共对象getItem(int位置){
返回位置;
}
@凌驾
公共长getItemId(int位置){
返回位置;
}
@凌驾
公共布尔值isEnabled(整型位置){
返回类型。获取(位置)!=0;
}
@TargetApi(Build.VERSION\u code.O)
公共视图getView(int位置、视图转换视图、视图组父视图){
//使用了新视图而不是convertView,因此微调器可以支持多个视图
视图=空;
//如果type等于0,它将加载作业头else jobs child
if(type.get(position)==0){
视图=充气机。充气(R.layout.lv_标题,空,假);
TextView header=view.findviewbyd(R.id.jobsheding);
header.setText(listItemArrayList.get(position.getValue());
如果(位置==0){
头.setTextSize(16);
header.setTypeface(context.getResources().getFont(R.font.ralway_regular));
header.setTextColor(context.getResources().getColor(R.color.colorPrimaryDark));
}否则{
header.setTextColor(context.getResources().getColor(R.color.colorBlack));
}
}else if(type.get(position)==1){
视图=充气机。充气(R.layout.lv_child,null,false);
TextView-child=view.findviewbyd(R.id.jobsChild);
setText(listItemArrayList.get(position.getValue());
}
返回视图;
}

}

如果它跳到任何图像项的主\u列表\u项目\u imgpast下载链接上,请尝试调试。是否“uriList.get(position).getDownloadLink()”返回正确的url?如果@AlexMamotry跳转到任何图像项的主\u列表\u项目\u imgpast下载链接上,请使用@Alexmotry进行调试。是否“uriList.get(position.getDownloadLink()”返回正确的url?请回复@AlexMamo