我知道有很多类似的问题,但我找不到我犯的错误,如果有人可以帮助。 我试图想聊天格式,但数组列表项的数组列表中显示的值上滚动查看持有人和自定义列表查看项目滚动时滚动
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(getActivity()).inflate(
R.layout.chat_row, parent, false);
holder = new ViewHolder();
holder.messageLeft = (TextView) convertView
.findViewById(R.id.leftBox);
holder.messageRight = (TextView) convertView
.findViewById(R.id.rightBox);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
try { if (snd_id.get(position).equalsIgnoreCase(appPref.getData("Uid"))) {
holder.messageLeft.setText(snd_name.get(position)+":"+"\n"+chat.get(position));
holder.messageLeft.setVisibility(View.VISIBLE);
holder.messageRight.setVisibility(View.GONE);
} else {
holder.messageRight.setText(snd_name.get(position)+":"+"\n"+chat.get(position));
holder.messageRight.setVisibility(View.VISIBLE);
holder.messageLeft.setVisibility(View.GONE);
}
} catch (Exception e) {
e.printStackTrace();
}
return convertView;
}
这里越来越错位的是视图holder类
private static class ViewHolder {
public TextView messageLeft;
public TextView messageRight;
}
高效和正确的方法,我甲肝编辑现在工作的菲英岛问题....感谢所有乌拉圭回合支持 –