2016-11-01 10 views
0

最初にリストビューを読み込むと正しいアイテムが表示されます。戻って再び読み込むと、アイテム全体が再び繰り返されます。繰り返しますが、私が戻って同じものをロードすると、エントリは再び繰り返されます。Androidリストビューアイテムが繰り返されます

例:最初は4つの項目、2番目の項目は8番目の項目、3番目の項目は12番目の項目などです。

以下は私のcustomarrayadapter'sgetView()の方法です。

パブリッククラスCustomArrayAdapterHistoryはArrayAdapter {

ArrayList<RequestHistory> historyList = new ArrayList<>(); 
private Context context; 

public CustomArrayAdapterHistory(Context context, int textViewResourceId, ArrayList<RequestHistory> objects) { 
    super(context, textViewResourceId, objects); 
    historyList = objects; 
    this.context=context; 
} 

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

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 

    View v = convertView; 
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    v = inflater.inflate(R.layout.request_history_items, null); 
    TextView textView1 = (TextView) v.findViewById(R.id.textView1); 
    TextView textView2 = (TextView) v.findViewById(R.id.textView2); 
    TextView textView3 = (TextView) v.findViewById(R.id.textView3); 
    ImageView imageView= (ImageView) v.findViewById(R.id.imageView); 
    TextView date= (TextView) v.findViewById(R.id.date); 

    Log.e("Date","....."+historyList.get(position).getDate()); 
    date.setText(historyList.get(position).getDate()); 
    if(historyList.get(position).getserviceName()!="null") 
     if(historyList.get(position).getserviceName()!="") 
      textView1.setText(historyList.get(position).getserviceName()); 
    if(historyList.get(position).getreplyNote().equals("")){ 
     textView3.setVisibility(View.INVISIBLE); 
    } 
    else { 
     textView3.setText("Reply: " + historyList.get(position).getreplyNote()); 
    } 
    textView2.setText("Booking Details: " + historyList.get(position).getBookingdetails()); 


    if(historyList.get(position).getStatus().equals("0")){ 
     imageView.setBackgroundResource(R.drawable.pending); 
    } 
    else if(historyList.get(position).getStatus().equals("1")){ 
     Log.e("STATUS ID","....."+historyList.get(position).getStatus()); 
     imageView.setBackgroundResource(R.drawable.cross); 
    } 
    else if(historyList.get(position).getStatus().equals("2")){ 
     imageView.setBackgroundResource(R.drawable.tick); 
    } 
    return v; 

この問題を解決するために私を助けてくださいを拡張します。

+1

古いリスト –

+1

を削除 – Vickyexpert

+0

があなたのコンストラクタを投稿ListViewコントロールするアダプタを設定するためのロジックを示して、私はあなた 'historyList'初期どのように見てみたいです。私は問題が最初に –

答えて

0

あなたのGetViewメソッド項目は、お使いのアダプタのコンストラクタでこの

if(convertView == null){ 
     //We must create a View: 
     convertView = inflater.inflate(R.layout.my_list_item, parent, false); 
    } 
    //Here we can do changes to the convertView, such as set a text on a TextView 
    //or an image on an ImageView. 
    return convertView; 
+1

これはパフォーマンスのためだけです。それは問題を助けません。彼の問題は 'getCount()'メソッドにあります。おそらく 'getItem()'メソッドにあります。 –

0

チェック三番目のパラメータArrayList<RequestHistory> objectsようにする必要があります。コンストラクタを呼び出すたびに展開されます。

0

getCountを変更しても、アダプタに問題はありません。アダプターを使用するアクティビティーでは、呼び出す前にアダプターのコンストラクターに渡すリストをクリアして、再割り当てする必要があります。

@Override 
public int getCount() { 
    return historyList.size(); 
} 
関連する問題