我知道有很多類似的問題,但我找不到我犯的錯誤,如果有人可以幫助。 我試圖想聊天格式,但數組列表項的數組列表中顯示的值上滾動查看持有人和自定義列表查看項目滾動時滾動
@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;
}
高效和正確的方法,我甲肝編輯現在工作的菲英島問題....感謝所有烏拉圭回合支持 –