您的位置:首页技术文章
文章详情页

android - 使用listview加载不同item,数据填充错误。

【字号: 日期:2024-09-11 11:15:33浏览:69作者:猪猪

问题描述

当日期的值为空的时候,就会将姓名或邮箱等值填充进去,当日期有值的时候现实正常,找了好久不知道怎么搞,希望各位大神给点建议。android - 使用listview加载不同item,数据填充错误。

android - 使用listview加载不同item,数据填充错误。

下面为adapter的代码:

private static final int TYPE_VIEW_COUNT = 2;private static final int TYPE_ONE = 0;private static final int TYPE_TWO = 1;private List<FormData> mDatas;private Context mContext;private LayoutInflater mInflater;private int eventIds = -1;private int attendIds = -1;private int ticketIds = -1;private Attends attends;private EventTicket ticket;private JSONObject object = null;public DetailAdapter(List<FormData> mDatas, Context mContext, int eventId, int attendId, int ticketId) { this.mDatas = mDatas; this.mContext = mContext; this.mInflater = LayoutInflater.from(mContext); this.eventIds = eventId; this.attendIds = attendId; this.ticketIds = ticketId;attends = new Select().from(Attends.class).where(Attends_Table.eventId.is(eventIds)).and(Attends_Table.attendId.is(attendIds)).querySingle(); ticket = new Select().from(EventTicket.class).where(EventTicket_Table.eventIds.is(eventIds)).and(Attends_Table.ticketIds.is(ticketIds)).querySingle(); try {object = new JSONObject(attends.gsonUser); } catch (JSONException e) {e.printStackTrace(); }}@Overridepublic int getItemViewType(int position) { if (position == 0) {return TYPE_ONE; } else {return TYPE_TWO; }}@Overridepublic int getViewTypeCount() { return TYPE_VIEW_COUNT;}@Overridepublic int getCount() { return mDatas.size() + 1;}@Overridepublic Object getItem(int position) { return mDatas.get(position);}@Overridepublic long getItemId(int position) { return position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) { DetailViewHolder holder = null; UserDetailViewHolder userDetailViewHolder = null; int viewTypeCount = getItemViewType(position); if (convertView == null) {switch (viewTypeCount) { case TYPE_ONE:userDetailViewHolder = new UserDetailViewHolder();convertView = mInflater.inflate(R.layout.attend_people_datail_type1, null);userDetailViewHolder.tv_name_letter = (CircleTextView) convertView.findViewById(R.id.tv_detail_letter);userDetailViewHolder.tv_detail_name = (TextView) convertView.findViewById(R.id.tv_detail_name);userDetailViewHolder.tv_ticket_name = (TextView) convertView.findViewById(R.id.tv_detail_ticket);convertView.setTag(userDetailViewHolder); // AutoUtils.auto(convertView);break; case TYPE_TWO:holder = new DetailViewHolder();convertView = mInflater.inflate(R.layout.attend_people_datail_type2, null);holder.tv_form = (TextView) convertView.findViewById(R.id.tv_form);holder.tv_detail_content = (TextView) convertView.findViewById(R.id.tv_detail_content);convertView.setTag(holder);} } else {switch (viewTypeCount) { case TYPE_ONE:userDetailViewHolder = (UserDetailViewHolder) convertView.getTag();break; case TYPE_TWO:holder = (DetailViewHolder) convertView.getTag();break;} } //根据返回类型展示不同的数据 switch (viewTypeCount) {case TYPE_ONE: if (attends != null && ticket != null) {userDetailViewHolder.tv_name_letter.setText(attends.names.substring(0, 1));userDetailViewHolder.tv_detail_name.setText(attends.names);userDetailViewHolder.tv_ticket_name.setText(ticket.ticketNames); } break;case TYPE_TWO: if (position >= 1) {Log.e('', 'position -->' + position);if (attends != null) { holder.tv_form.setText(mDatas.get(position - 1).getFormName()); try {if (object != null) { holder.tv_detail_content.setText(object.getString(mDatas.get(position - 1).getFormFieldId() + ''));}// Toast.makeText(mContext, holder.tv_form.getText().toString(), Toast.LENGTH_LONG).show(); // Toast.makeText(mContext, holder.tv_detail_content.getText().toString(), Toast.LENGTH_LONG).show(); } catch (JSONException e) {e.printStackTrace(); }} } break; } return convertView;}class DetailViewHolder { TextView tv_form; TextView tv_detail_content;}class UserDetailViewHolder { CircleTextView tv_name_letter; TextView tv_detail_name; TextView tv_ticket_name;}

}

问题解答

回答1:

@Overridepublic int getCount() {

return mDatas.size() + 1;

}不需要加一吧