添加新列表项然后滚动时会给出错误,但在getviewTypeCount`内返回类似300或更大的数字时,它不会给出如何解决的错误 并在创建和设置新消息时滚动其给定错误。这个列表视图有两个不同的布局mymessage和其他消息,我为此功能,一切工作正常,但滚动问题。该怎么解决?
public class ChatAdapter extends BaseAdapter {
private Context context;
private ArrayList<ChatMessage> chatMessages;
RequestOptions options;
private int SELF = 786;
private static final int REGULAR = 0;
private static final int HEADER = 1;
public ChatAdapter (Context context, ArrayList<ChatMessage> chatMessages){
this.context = context;
this.chatMessages = chatMessages;
options = new RequestOptions().circleCrop().placeholder(R.drawable.loader).error(R.drawable.loader);
}
@Override
public int getViewTypeCount() {
return getCount();
}
@Override
public int getItemViewType(int position) {
return position;
}
@Override
public int getCount() {
return chatMessages.size();
}
@Override
public ChatMessage getItem(final int position) {
return chatMessages.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Intent intent = ((Activity) context).getIntent();
String sno = intent.getStringExtra("sno");
String userid = chatMessages.get(position).getUserId();
if (userid.equals(sno)) {
convertView = inflater.inflate(R.layout.mymessage, null, true);
}else {
convertView = inflater.inflate(R.layout.message, null, true);
}
// convertView = inflater.inflate(R.layout.message, null, true);
holder.user_name = (TextView) convertView.findViewById(R.id.user_name);
holder.time = (TextView) convertView.findViewById(R.id.timec);
holder.message = (TextView) convertView.findViewById(R.id.msg);
holder.filename = (TextView) convertView.findViewById(R.id.file_name);
holder.file = (ImageView) convertView.findViewById(R.id.file_img);
holder.view_container = convertView.findViewById(R.id.all_msg);
holder.view_container = convertView.findViewById(R.id.my_all);
convertView.setTag(holder);
}else {
holder = (ViewHolder) convertView.getTag();
}
holder.user_name.setText(chatMessages.get(position).getMessageUser());
holder.time.setText(" " +chatMessages.get(position).getMessageTime());
holder.message.setText(chatMessages.get(position).getMessageText());
holder.filename.setText(chatMessages.get(position).getFileName());
Glide.with(context).load(chatMessages.get(position).getMessageFile()).into(holder.file);
Linkify.addLinks(holder.message,Linkify.ALL);
return convertView;
}
private class ViewHolder {
protected TextView user_name, time, message, filename;
ImageView file;
EditText sentmsg;
protected LinearLayout view_container;
}
}