ための正しいビュータイプのconvertviewを提供しますので、あなたがリサイクルビューを心配する必要はありません
static public enum LAYOUT_TYPE {
INBOUND,
OUTBOUND
}
@Override
public int getViewTypeCount() {
return LAYOUT_TYPE.values().length;
}
@Override
public int getItemViewType (int position) {
if (messages.get(position).isOutbound())
return LAYOUT_TYPE.OUTBOUND.ordinal();
else
return LAYOUT_TYPE.INBOUND.ordinal();
}
@Override
public View getView (int position, View convertView, ViewGroup parent) {
LAYOUT_TYPE itemType = LAYOUT_TYPE.values()[getItemViewType(position)];
... (code until inflater)
switch (itemType){
case INBOUND:
convertview = /inflate & configure inbound layout
break;
case OUTBOUND:
convertview = /inflate & configure outbound layout
break;
}
このような:これは良い習慣であるか、if (v == null)
を削除しても問題が解決するかどうかではない
ViewHolder holder;
public View getView(int position, View convertView, ViewGroup parent) {
convertView = null;
SoapBoxMessage thisMessage = messages.get(position);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (thisMessage.isOutbound()) {
convertView = inflater.inflate(R.layout.outbound, null, false);
//specific to your outbound layout
holder = new ViewHolder();
holder.text= (TextView)convertView.findViewById(R.id.textview);
holder.group = (RadioGroup)convertView.findViewById(R.id.toggleGroup);
holder.toggle = (ToggleButton)convertView.findViewById(R.id.toggleButton);
} else {
convertView = inflater.inflate(R.layout.inbound, null, false);
//specific to your inbound layout
holder = new ViewHolder();
holder.text= (TextView)convertView.findViewById(R.id.textview);
holder.group = (RadioGroup)convertView.findViewById(R.id.toggleGroup);
holder.toggle = (ToggleButton)convertView.findViewById(R.id.toggleButton);
}
convertView.setTag(holder);
}
else{
holder = (ViewHolder) convertView.getTag();
}
//Here you can set the text or other code you want to implement
holder.text.setText("Whatever!");
return convertView;
}
static class ViewHolder {
//TODO put components you use like:
TextView text;
RadioGroup group;
ToggleButton toggle;
}
こんにちは...このような単純な間違いは私の一部です。それに気づいてくれてありがとう。パフォーマンスが最適であることを確認するために何か他のことをすることをお勧めしますか? – GuyLeStack
実際にはifステートメントを単に削除するだけでレイアウトの問題は解決されますが、後でアダプタで動的に追加される他のビューではさらに問題が発生します。アイデア? – GuyLeStack
その他のビューは?コードを見ることはできますか? –