ListView适配器与毕加索

问题描述 投票:0回答:1

我使用自定义适配器列出一些用户,我想列出一些图片扔Firebase,我使用Picasso,但我无法在列表中显示图片,在步骤中显示网址。

这是适配器:

public class customAdapter extends ArrayAdapter<UserInformation> {

private Context context;
private LayoutInflater inflater;


public customAdapter(Context context, int layoutResource, List<UserInformation> userInformationsList) {
    super(context, layoutResource, userInformationsList);

    this.context=context;
    inflater = LayoutInflater.from(context);
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {



    View view = convertView;

    if (view == null) {
        LayoutInflater layoutInflater = LayoutInflater.from(getContext());
        view = layoutInflater.inflate(R.layout.userslist, null);
    }

    UserInformation userInformation = getItem(position);

    if (userInformation != null) {
        TextView Name = (TextView) view.findViewById(R.id.textNameList);
        //name.setText(name[position]);
        ImageView mPicture = (ImageView) view.findViewById(R.id.imageViewPicture);
        String uri ;
        //email.setText(Email[position]);
        TextView gender = (TextView) view.findViewById(R.id.textGenderList);
        //gender.setText(Gender[position]);
        TextView birthday = (TextView) view.findViewById(R.id.textBirthdayList);
        //birthday.setText(Birthday[position]);

        if (Name != null) {
            Name.setText(userInformation.getName());
        }
        if (mPicture != null) {
            uri=(userInformation.getUri());
            Picasso.with(context).load(uri).fit().centerCrop().into(mPicture);

        }
        if (gender != null) {
            gender.setText(userInformation.getGender());
        }
        if (birthday != null) {
            birthday.setText(userInformation.getBirthday());
        }
    }

    return view;
}
}

这就是结果:

Capture

这是.XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/colorEditText">


<ImageView
    android:layout_marginTop="30dp"
    android:layout_marginLeft="30dp"
    android:id="@+id/imageViewPicture"
    android:layout_width="50dp"
    android:layout_height="50dp" />

<TextView
    android:id="@+id/textNameList"
    android:textSize="25dp"
    android:textAlignment="textStart"
    android:text="Name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="start"
    android:layout_margin="10dp"/>

<TextView
    android:id="@+id/textEmailList"
    android:textSize="15dp"
    android:textAlignment="textStart"
    android:text="Age"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="start"
    android:layout_margin="10dp"/>
<TextView
    android:id="@+id/textBirthdayList"
    android:textSize="15dp"
    android:textAlignment="textStart"
    android:text="Birthday"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="start"
    android:layout_margin="10dp"/>
<TextView
    android:id="@+id/textGenderList"
    android:textSize="15dp"
    android:textAlignment="textStart"
    android:text="gender"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="start"
    android:layout_margin="10dp"/>


</LinearLayout> 

有什么建议吗?

提前致谢。

android firebase picasso listview-adapter
1个回答
0
投票

在你向picasso添加url之前检查天气是否有效,如果有效,那么在getView()中尝试下面这段代码也会删除fit().centerCrop(),因为如果图像很大则不会设置。如果你在xml中添加android:src="@drawable/ic_launcher"属性,那么也删除它。并检查Manifest您是否添加Internet权限。

<uses-permission android:name="android.permission.INTERNET" />

并使用这个:

if (mPicture != null) {
    Picasso.with(context).load(userInformation.getUri()).into(mPicture);
   }

希望它会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.