2017-05-30 63 views

回答

0

試試這個代碼: -

public class MyProfileArrayAdapter extends BaseAdapter { 

Context context; 

ArrayList<MyProfileBean> myProfileBeen1; 
View gridViewAndroid; 

public MyProfileArrayAdapter(Context context, ArrayList<MyProfileBean> myProfileBeen1) { 
    this.context = context; 
    this.myProfileBeen1 = myProfileBeen1; 

} 

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

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

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

@Override 
public int getViewTypeCount() { 
    int Count = myProfileBeen1.size; 
    return Count; 
} 

@Override 
public int getItemViewType(int position) { 
    return position; 
} 


    /*private view holder class*/ 


public View getView(int position, View convertView, ViewGroup parent) { 
    final ViewHolder holder; 

    if (convertView == null) { 

     LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE); 

     convertView = inflater.inflate(R.layout.myprofile_adapter, parent, false); 


     holder.view2 = (TextView) convertView.findViewById(R.id.UrlimageText); 

     holder.view4 = (ImageView) convertView.findViewById(R.id.Urlimage); 
    } 
    else { 
     holder = (ViewHolder) convertView.getTag(); 
    } 
    holder.view2.setText(myProfileBeen1.get(position).getName()); 


    if (myProfileBeen1.get(position).getUrl().equals("")) { 
     Picasso.with(this.context) 
       .load(R.drawable.defaultbignewone) 
       .centerCrop() 
       .noFade() 
       .resize(150, 150) 

       .error(R.drawable.defaultbignewone) 
       .into(holder.view4); 

    } else { 
     Picasso.with(context) 
       .load(myProfileBeen1.get(position).getUrl()) 
       .placeholder(R.drawable.defaultbignewone) 
       .centerCrop() 
       .noFade() 
       .resize(150, 150) 
       .into(holder.view4); 
    } 


    return convertView; 

} 

private static class ViewHolder { 

    TextView view2; 
    ImageView view4; 

} 

}

+1

不工作.. :( –

+0

你試過上面的代碼嗎?讓我知道。 –