キー/値のペアの行ごとに2つのTextViewを持つカスタムListviewに詳細な製品情報を表示しようとしています。データが正しく表示されます。私はまた、違うセカンドラインを着色しました。Android - カスタムListViewビューア
私の問題があります。上下にスクロールすると、異なる色の行が色を変えてこの状態に留まります。データはこの問題の影響を受けません。 TextViewのバックグラウンドカラー。私はViewHolderパターンを使用しますが、これは何も変わりません。アダプターのコードを追加しました。私は十分だと思う。何かお考えですか?問題の
スクリーンショット:
コード:
public class ProductDetailAdapter extends BaseAdapter {
private LinkedHashMap<String,String> list;
private Context context;
public ProductDetailAdapter(Context c, LinkedHashMap<String,String> list){
super();
this.context = c;
this.list=list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ProductDetailAdapter.ViewHolder viewHolder;
if(convertView == null){
convertView=inflater.inflate(R.layout.product_detail_data_row,null);
viewHolder = new ViewHolder();
viewHolder.textViewKey = (TextView) convertView.findViewById(R.id.productDataKey);
viewHolder.textViewValue = (TextView) convertView.findViewById(R.id.productDataValue);
convertView.setTag(viewHolder);
}else {
viewHolder = (ProductDetailAdapter.ViewHolder) convertView.getTag();
}
viewHolder.textViewKey.setText((String)list.keySet().toArray()[position]);
viewHolder.textViewValue.setText(list.get(list.keySet().toArray()[position]));
if(position % 2 == 0){
viewHolder.textViewKey.setBackgroundColor(context.getResources().getColor(R.color.colorParkerWhite2));
viewHolder.textViewValue.setBackgroundColor(context.getResources().getColor(R.color.colorParkerWhite2));
}
return convertView;
}
private static class ViewHolder {
public TextView textViewKey;
public TextView textViewValue;
public ViewHolder(){};
}
}
のために動作します参照してください。あなたの質問を編集してください。感謝! – aldakur
image url:https://i.stack.imgur.com/OS3Op.pngはうまく動作します – Mike
'if(position%2 == 0)'の中に新しい 'ViewHolderインスタンス'を作成してみてください – aldakur