我需要在Android Studio中創建一個具有文本和與該文本相對應的圖像的listView。我知道我必須製作自己的自定義適配器,但是我不知道如何使它不僅僅是每行中的文本視圖。適配器將接收文本的字符串數組,以及與圖片對應的另一個url的字符串數組。我怎樣才能創建這個適配器來做到這一點。我最好喜歡使用畢加索,但如果你有任何其他建議也可以。使用一串文字和一串圖像使用picasso創建ListView
class MyAdapter extends ArrayAdapter <String> {
Context context;
String[] descriptionArray;
String[] url;
MyAdapter (Context c, String[] importerArray,String[] url) {
super(c, R.layout.content_orders,R.id.textView2, importerArray);
this.context =c;
this.descriptionArray = importerArray;
this.url = url;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.content_orders, list, false);
ImageView myImage = (ImageView) row.findViewById(R.id.imageView2);
TextView description = (TextView) row.findViewById(R.id.textView2);
description.setText(descriptionArray[position]);
Picasso.with(OrdersActivity.this).load(url[position]).into(myImage);
return convertView;
}
請告訴我們你有什麼到目前爲止已經試過。謝謝。 –
@GennadiiSaprykin我道歉。我現在更新了它。 – Kekis2014