2017-12-22 9 views
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; 
} 
} 

そして、これが結果です:

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> 

どれ暗示?

ありがとうございます。

+1

イメージがロードされていないと言って、Piccatsoからlogcatにエラーがありますか? –

+1

ブラウザでURLを試してみるとうまくいけば、それだけでピカソで動作します –

+0

あなたのxmlを共有します。 –

答えて

0

picassoにURLを追加する前に、天気が有効かどうかを確認してください。有効な場合はgetView()のコードを削除してください。fit().centerCrop()イメージが大きい場合は設定されません。 android:src="@drawable/ic_launcher"プロパティをxmlに追加した場合は、これも削除してください。 Manifestにインターネット許可を追加するかどうかをチェックしてください。

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

、これを使用します。

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

はそれに役立つことを願っています。

関連する問題