2017-06-15 12 views
0

私はデータ、つまり画像、テキスト、画像、テキストを追加することができないので、画像で示されるカスタムリストビューを作成します。 誰でも私をリストビューでデータを入力するように誘導できますか? 私は1つのテキストと1つのイメージを使っていましたが、今はこれらの2つのテキストと2つのイメージが必要です。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 

答えて

0

すべてのデータを持つBeanクラスを作成します。

次に、カスタムBeanクラスArrayList<YourBean>の配列リストをアダプターに渡します。

次に、BaseAdapterクラスで拡張してカスタムアダプタを作成します。

+0

あなたのplzが私にこれの例を教えてくれますか? –

+0

http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/をご覧ください –

関連する問題