0
私はカスタムアダプタを使用していくつかのユーザをリストアップしていますが、をスローすると、Picasso
が使用されていますが、リストの画像を表示することはできません。 。ListViewアダプタwith 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>
どれ暗示?
ありがとうございます。
イメージがロードされていないと言って、Piccatsoからlogcatにエラーがありますか? –
ブラウザでURLを試してみるとうまくいけば、それだけでピカソで動作します –
あなたのxmlを共有します。 –