0

我将在 textview 中显示具有固定标题 invno 日期等的详细信息。而下面是列表视图,它与客户适配器一起显示,并在最后一行显示,在客户适配器中以不同的颜色显示在此处输入图像描述

但是当我滚动两三次时会导致这样的问题在此处输入图像描述

这是我的客户适配器

public class CustomAdapter extends BaseAdapter {
private Activity activity;
    private LayoutInflater inflater=null;
    private RelativeLayout relativeCel;
    private ArrayList<String> listidA=new ArrayList<String>();
    private ArrayList<String> listDateA=new ArrayList<String>();
    private ArrayList<String> lisTotalAMTA=new ArrayList<String>();
    private ArrayList<String> listPaymenIdA=new ArrayList<String>();
    private ArrayList<String> listPaymenNameA=new ArrayList<String>();
    private Float total=0.0f;


    /**
     * 
     * @param a
     * @param listid
     * @param listDate
     * @param lisTotalAMT
     * @param listPaymenId
     * @param listPaymenName
     */
    public CustomAdapter(Activity a,ArrayList<String>listid,ArrayList<String>listDate,ArrayList<String>lisTotalAMT,ArrayList<String>listPaymenId,ArrayList<String>listPaymenName) {
        inflater = (LayoutInflater)a.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.activity=a;
        this.listidA=listid;
        this.listDateA=listDate;
        this.lisTotalAMTA=lisTotalAMT;
        this.listPaymenIdA=listPaymenId;
        this.listPaymenNameA=listPaymenName;
        total=0.0f;

        for(int i=0;i<listidA.size();i++)
            total=total+(Float.parseFloat(""+lisTotalAMTA.get(i)));

    }
    public int getCount() {
        return listidA.size()+1;
    }
    public Object getItem(int position) {
        return position;
    }
    public long getItemId(int position) {
        return position;
    }
    public class ViewHolder{
        TextView txtInvoiceNo,txtDate,txtPaymentMode ,txtPamentAmount;
    }
    @SuppressLint("NewApi")
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;

        if (convertView == null) {
            AppLog.logString(TAG+"if Null: "+position);
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = vi.inflate(R.layout.item_sales_report, null);
            holder = new ViewHolder();
            holder.txtInvoiceNo = (TextView)convertView.findViewById(R.id.txtInvoiceNo);
            holder.txtDate = (TextView)convertView.findViewById(R.id.txtDate);
            holder.txtPaymentMode = (TextView)convertView.findViewById(R.id.txtPaymentMode); 
            holder.txtPamentAmount = (TextView)convertView.findViewById(R.id.txtPamentAmount);

            convertView.setTag(holder);
        } else {
            AppLog.logString(TAG+"else Null: "+position);
            holder = (ViewHolder) convertView.getTag();
        }

        if(position-1==listPaymenIdA.size()-1){
            //AppLog.logString(TAG+"if: "+position);
            int color=getResources().getColor(R.color._90ffffff);
            holder.txtInvoiceNo.setBackgroundColor(color);
            holder.txtDate.setBackgroundColor(color);
            holder.txtPamentAmount.setBackgroundColor(color);
            holder.txtPaymentMode.setBackgroundColor(color);

            holder.txtInvoiceNo.setTypeface(null, Typeface.BOLD);
            holder.txtDate.setTypeface(null, Typeface.BOLD);
            holder.txtPamentAmount.setTypeface(null, Typeface.BOLD);
            holder.txtPaymentMode.setTypeface(null, Typeface.BOLD);

            holder.txtInvoiceNo.setText("");
            holder.txtDate.setText("Total ");
            holder.txtPamentAmount.setText(""+round(total));
            holder.txtPaymentMode.setText("");
        }else{
            //AppLog.logString(TAG+"else: "+position);
            Date date1 = null;
            try {
                date1 = new SimpleDateFormat("yyyy/MM/dd").parse(listDateA.get(position));
            } catch (ParseException e) {
                e.printStackTrace();
            }

            formatterYY = new SimpleDateFormat("dd/MM/yyyy", Locale.US);
            String todaye = formatterYY.format(date1);
            holder.txtInvoiceNo.setText(""+listidA.get(position));
            holder.txtDate.setText(""+todaye);
            holder.txtPaymentMode.setText(""+listPaymenNameA.get(position));
            holder.txtPamentAmount.setText(""+round(lisTotalAMTA.get(position)));
        }
        return convertView;
    }
}
4

2 回答 2

0

将此代码放在您的列表视图中,

android:cacheColorHint = "#000000". 
于 2013-10-21T06:34:05.847 回答
0

只是改变

if(position-1==listPaymenIdA.size()-1){
        //AppLog.logString(TAG+"if: "+position);
        int color=getResources().getColor(R.color._90ffffff);
        holder.txtInvoiceNo.setBackgroundColor(color);
        holder.txtDate.setBackgroundColor(color);
        holder.txtPamentAmount.setBackgroundColor(color);
        holder.txtPaymentMode.setBackgroundColor(color);

        holder.txtInvoiceNo.setTypeface(null, Typeface.BOLD);
        holder.txtDate.setTypeface(null, Typeface.BOLD);
        holder.txtPamentAmount.setTypeface(null, Typeface.BOLD);
        holder.txtPaymentMode.setTypeface(null, Typeface.BOLD);

        holder.txtInvoiceNo.setText("");
        holder.txtDate.setText("Total ");
        holder.txtPamentAmount.setText(""+round(total));
        holder.txtPaymentMode.setText("");
    }else{
        //AppLog.logString(TAG+"else: "+position);
        Date date1 = null;
        try {
            date1 = new SimpleDateFormat("yyyy/MM/dd").parse(listDateA.get(position));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        int color=getResources().getColor(R.color._10ffffff);//normal color which display
        holder.txtInvoiceNo.setBackgroundColor(color);
        holder.txtDate.setBackgroundColor(color);
        holder.txtPamentAmount.setBackgroundColor(color);
        holder.txtPaymentMode.setBackgroundColor(color);

        holder.txtInvoiceNo.setTypeface(null, Typeface.NORMAL);
        holder.txtDate.setTypeface(null, Typeface.NORMAL);
        holder.txtPamentAmount.setTypeface(null, Typeface.NORMAL);
        holder.txtPaymentMode.setTypeface(null, Typeface.NORMAL);

        formatterYY = new SimpleDateFormat("dd/MM/yyyy", Locale.US);
        String todaye = formatterYY.format(date1);
        holder.txtInvoiceNo.setText(""+listidA.get(position));
        holder.txtDate.setText(""+todaye);
        holder.txtPaymentMode.setText(""+listPaymenNameA.get(position));
        holder.txtPamentAmount.setText(""+round(lisTotalAMTA.get(position)));
    }
于 2014-08-29T10:44:34.157 回答