我正在尝试实现一个列表,该列表从我的ORM数据库中获取聊天并将其显示在列表中。聊天内容非常整齐地被提取和显示,但是当我将键盘输入键入消息时,聊天值在list get jumbled。我已按时间戳的升序获取聊天值。 这是我的适配器...
public class ChatsAdapter extends CursorAdapter {
private Context mContext;
private LayoutInflater mInflater;
private ContactInfo contact;
private Chat item;
private Cursor c;
public ChatsAdapter(Context context, Cursor c, boolean autoRequery, ContactInfo contact) {
super(context, c, false);
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mContext = context;
this.contact = contact;
this.c = c;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
ViewHolder holder = new ViewHolder();
View v = null;
if (cursor.getInt(cursor.getColumnIndex(Chat.COLMN_IS_ME)) > 0) {
v = mInflater.inflate(R.layout.incoming_message, parent, false);
holder._name = (TextView) v
.findViewById(R.id.profile_name);
holder._text = (TextView) v
.findViewById(R.id.text);
holder._time = (TextView) v
.findViewById(R.id.time);
String name = SharedPerefsUtil.getSharedPreferencesString(context, Constants.NAME, "");
holder._name.setText(name);
holder._time.setText(Util.getTime(cursor.getLong(cursor.getColumnIndex(Chat.COLMN_TIME))));
holder._text.setText(cursor.getString(cursor.getColumnIndex(Chat.COLMN_TEXT)));
} else {
v = mInflater.inflate(R.layout.outgoing_msg, parent, false);
holder._name = (TextView) v
.findViewById(R.id.profile_name);
holder._text = (TextView) v
.findViewById(R.id.text);
holder._time = (TextView) v
.findViewById(R.id.time);
holder._name.setText(contact.getName());
holder._text.setText(cursor.getString(cursor.getColumnIndex(Chat.COLMN_TEXT)));
holder._time.setText(Util.getTime(cursor.getLong(cursor.getColumnIndex(Chat.COLMN_TIME))));
}
v.setTag(holder);
return v;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
}
@Override
public int getItemViewType(int position) {
Cursor cursor = (Cursor) getItem(position);
return getItemViewType(cursor);
}
@Override
public int getViewTypeCount() {
return 2;
}
private int getItemViewType(Cursor cursor) {
boolean type = cursor.getInt(cursor.getColumnIndex(Chat.COLMN_FROM_ME)) > 0;
if (type) {
return 0;
} else {
return 1;
}
}
public class ViewHolder {
public TextView _name;
public TextView _time;
public TextView _text;
public ImageView _image;
}
}
任何帮助表示感谢..提前感谢..