タイトルにあるように、ListView をスクロールすると、アイテムが行を切り替え続けます。私はすでに同じ問題についてここで読みましたが、何が間違っていたのかわかりません。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View row = convertView;
RecordHolder holder = null;
Object o = getItem(position);
if (row == null) {
LayoutInflater inflater = activity.getLayoutInflater();
row = inflater.inflate(R.layout.chatmessageitem,null);
holder = new RecordHolder();
holder.txtMessage = (TextView) row.findViewById(R.id.txttextmessage);
holder.messageBubble = (ImageView) row.findViewById(R.id.chatbubble);
if(o instanceof MessageObject){
MessageObject m = (MessageObject) o;
if(m.getEmpfänger() != ((GlobalClass) context).myChatID){
holder.ID = m.getEmpfänger();
}else{
holder.ID =((GlobalClass) context).myChatID;
}
holder.message =(m.getMessage());
}
row.setTag(holder);
}else{
holder = (RecordHolder)row.getTag();
}
if(o instanceof MessageObject){
MessageObject msg = (MessageObject)o;
holder.txtMessage.setText(msg.getMessage());
if(holder.ID != ((GlobalClass) context).myChatID){
holder.messageBubble.setImageBitmap(BitmapFactory.decodeResource(context.getResources(), R.drawable.bubbleone));
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
holder.txtMessage.setText(holder.message);
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
holder.messageBubble.setLayoutParams(lp);
}else{
holder.messageBubble.setImageBitmap(BitmapFactory.decodeResource(context.getResources(), R.drawable.bubbletwo));
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
holder.txtMessage.setText(holder.message);
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
holder.messageBubble.setLayoutParams(lp);
}
}
return row;
}
static class RecordHolder {
String message;
int ID;
TextView txtMessage;
ImageView messageBubble;
}
事前に回答がある場合はthx。よろしく。