我正在使用自定义适配器列出一些用户,我想列出一些图片投放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;
}
}
这就是结果:
这是.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>
任何消化?
提前致谢。
答案 0 :(得分:0)
在您向picasso添加网址之前,检查天气是否有效,如果有效,请在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);
}
希望它会有所帮助。