我已经显示了一个自定义列表视图,但是当我运行它时,列表视图项重复3次(可能是数组大小)。如何使列表视图显示非重复重复的项目?下面是我的代码。列表视图项重复在android
public class lvAdapter extends BaseAdapter implements OnClickListener {
private Context context;
String festi,weekd,datee;
List<FestPOJO> listPhonebook = PublicHolidays.listOffests;
public lvAdapter(Context context, List<FestPOJO> listPhonebook) {
this.context = context;
this.listPhonebook = listPhonebook;
}
public int getCount() {
return listPhonebook.size();
}
public Object getItem(int position) {
return listPhonebook.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup viewGroup) {
FestPOJO inst = listPhonebook.get(position);
if (convertView == null)
{
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.phone_row, null);
}
TextView tvContact = (TextView) convertView.findViewById(R.id.tvContact);
tvContact.setText(inst.getName());
TextView tvPhone = (TextView) convertView.findViewById(R.id.tvMobile);
tvPhone.setText(inst.getDay());
TextView tvMail = (TextView) convertView.findViewById(R.id.tvMail);
tvMail.setText(inst.getHalfdate());
return convertView;
}
@Override
public void onClick(View v) {
}
@Override
public int getViewTypeCount() {
System.out.println("getviewtypecount"+getCount());
return super.getViewTypeCount();
}
}
这是我FestPOJO类:
public class FestPOJO {
int weekend, opt, bank, year, id, date;
String name, month, day,halfdate;
public FestPOJO(String name, String day, String halfdate) {
this.name = name;
this.day = day;
this.halfdate = halfdate;
}
public String getHalfdate() {
return halfdate;
}
public void setHalfdate(String halfdate) {
this.halfdate = halfdate;
}
public int getWeekend() {
return weekend;
}
public void setWeekend(int weekend) {
this.weekend = weekend;
}
public int getOpt() {
return opt;
}
public void setOpt(int opt) {
this.opt = opt;
}
public int getBank() {
return bank;
}
public void setBank(int bank) {
this.bank = bank;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getDate() {
return date;
}
public void setDate(int date) {
this.date = date;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
public String getDay() {
return day;
}
public void setDay(String day) {
this.day = day;
}
}
任何帮助是提前多appreciated.Thanks。
阵列可能具有重复值之后错误的。所以必须确保数组中没有重复的条目。 – 2012-01-11 07:38:38
@UsamaSarwar数组值不会重复。我通过在logcat中打印来检查它,并在sqlbrowser中查询它。 – 2012-01-11 09:08:09