我将在textview中显示具有固定标题invno日期等的详细信息。下面是listview与客户adpter一起显示,在最后一行显示,总共有不同颜色的客户版权
但是当我滚动两次三次会引起问题,如
这是我的客户权限
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;
}
}
答案 0 :(得分:0)
将此代码放入列表视图
android:cacheColorHint = "#000000".
答案 1 :(得分: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)));
}