我使用視圖保持器創建自定義列表視圖並嘗試將正確的數據設置爲列表視圖。我已經alredy檢查我的適配器中的所有值它的retune getcount 7但是當我有加載數據的前兩個位置是正確的和其他行再次打印0和1 position.and一些時間顯示其他行數據到這個位置我不知道我最近怎麼了?請幫助:(爲ListViews創建適配器,但是爲什麼要將數據插入錯誤的位置
public class AdapterAppointment extends BaseAdapter {
private ArrayList<AppointmentInfoDto> AppointmentItemjbjects = new ArrayList<AppointmentInfoDto>();
private LayoutInflater layoutInflater;
Activity context;
ProgressDialog pg;
String techName="abhi";
LayoutInflater inflater;
public AdapterAppointment(Activity context, ArrayList<AppointmentInfoDto> AppointmentItemjbjects) {
this.context = context;
this.layoutInflater = LayoutInflater.from(context);
this.AppointmentItemjbjects=AppointmentItemjbjects;
}
@Override
public int getCount() {
return AppointmentItemjbjects.size();
}
@Override
public Object getItem(int position) {
return AppointmentItemjbjects.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
// convertView = layoutInflater.inflate(R.layout.activity_appointment, null);
inflater=LayoutInflater.from(context);
convertView=inflater.inflate(R.layout.activity_appointment,null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.txtServiceName = (TextView) convertView.findViewById(R.id.txtServiceName);
viewHolder.txtServiceAndSalesType = (TextView) convertView.findViewById(R.id.txtServiceAndSalesType);
viewHolder.txtName = (TextView) convertView.findViewById(R.id.txtName);
viewHolder.txtCompanyName = (TextView) convertView.findViewById(R.id.txtCompanyName);
viewHolder.txtInvoiceAmount = (TextView) convertView.findViewById(R.id.txtInvoiceAmount);
viewHolder.txtServicesAddress = (TextView) convertView.findViewById(R.id.txtServicesAddress);
viewHolder.txtServiceInstruction = (TextView) convertView.findViewById(R.id.txtServiceInstruction);
viewHolder.txtServiceDateAndTime = (TextView) convertView.findViewById(R.id.txtServiceDateAndTime);
viewHolder.txtStatus = (TextView) convertView.findViewById(R.id.txtStatus);
viewHolder.smsBtn = (AppCompatButton) convertView.findViewById(R.id.smsBtn);
viewHolder.emailBtn = (AppCompatButton) convertView.findViewById(R.id.emailBtn);
viewHolder.clickViewLayout = (RelativeLayout) convertView.findViewById(R.id.clickViewLayout);
viewHolder.txtAccountNo = (TextView) convertView.findViewById(R.id.txtAccountNo);
viewHolder.txtWorkOrderNo = (TextView) convertView.findViewById(R.id.txtWorkOrderNo);
viewHolder.txtServiceName.setText(AppointmentItemjbjects.get(position).getServices());
// viewHolder.txtServiceAndSalesType.setText(AppointmentItemjbjects.get(position).getServices());
viewHolder.txtName.setText(AppointmentItemjbjects.get(position).getFirstName()+""+AppointmentItemjbjects.get(position).getLastName());
viewHolder.txtCompanyName.setText(AppointmentItemjbjects.get(position).getCompanyName());
viewHolder.txtInvoiceAmount.setText("Invoice: $" +AppointmentItemjbjects.get(position).getInvoiceAmount());
viewHolder.txtServicesAddress.setText(AppointmentItemjbjects.get(position).getServicesAddress1()+", "+AppointmentItemjbjects.get(position).getServiceAddress2()+", "+AppointmentItemjbjects.get(position).getServiceCity()+", "+AppointmentItemjbjects.get(position).getServiceState()+" and "+AppointmentItemjbjects.get(position).getServiceZipcode());
viewHolder.txtServiceInstruction.setText(AppointmentItemjbjects.get(position).getServiceInstruction());
viewHolder.txtServiceDateAndTime.setText(DpsFunctionFlow.getDateFormatConvert(AppointmentItemjbjects.get(position).getServiceDateTime().toString()));
viewHolder.txtStatus.setText(AppointmentItemjbjects.get(position).getWorkorderStatus());
viewHolder.txtAccountNo.setText("Ac#: " + AppointmentItemjbjects.get(position).getAccountNo());
viewHolder.txtWorkOrderNo.setText("Wo#: "+AppointmentItemjbjects.get(position).getWorkOrderNo());
你一直插入數據時,如果(convertVieww == NULL){插入數據}其他{插入數據} –