0
我想創建自定義列表視圖,如圖所示,因爲我無法添加數據,即圖像,文本,圖像,文本 現在可以任何人都可以指導我在列表視圖中輸入數據? 我已經完成了一個文本和一個圖像,現在我想要這兩個文本和兩個圖像。在arrayadapter,自定義列表視圖中輸入多個項目(圖像,文本,圖像,文本)
android.widget.ListView viewall=(android.widget.ListView)findViewById(R.id.viewall);
final ArrayList<ViewReview> arrayList=new ArrayList<>();
ViewReview r1=new ViewReview();
ViewReview r2=new ViewReview();
ViewReview adapter=new ViewReview(this,arrayList);
viewall.setAdapter(adapter);
//--------------Adapter class
package com.example.ali_raza.cook;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
/**
* Created by Ali_Raza on 15-06-2017.
*/
public class ViewReview extends ArrayAdapter<Reviewlist> {
public ViewReview(Context context, ArrayList arraylist,Context c){
super(context,0,arraylist);
}
public View getView(int position, View view, ViewGroup parent){
View viewall=view;
LayoutInflater inflater=LayoutInflater.from(getContext());
if(view==null){
viewall=inflater.inflate(R.layout.reviewcustom,parent,false);
}
Reviewlist r=getItem(position);
ImageView image1=(ImageView)viewall.findViewById(R.id.userimage);
TextView text1=(TextView)viewall.findViewById(R.id.nameuser);
ImageView image2=(ImageView)viewall.findViewById(R.id.star);
TextView text2=(TextView)viewall.findViewById(R.id.paragraph);
image1.setImageResource(r.getRateimage());
text1.setText(r.getNameuser());
image2.setImageResource(r.getStar());
text2.setText(r.getRev());
return viewall;
}
}
[enter image description here][1]
[1]: https://i.stack.imgur.com/OBM6q.png
你的PLZ能爲我演示一個例子嗎? –
看看這個http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/ –