android fragment有listview,每次进入这个fragment,listview的item都会重复加载。如何解决?
Adapter部分代码publicclassListViewItemAdapterextendsBaseAdapter{@OverridepublicViewgetVie...
Adapter 部分代码
public class ListViewItemAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
try {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.layout_listview_item,
null);
holder.item_icon = (ImageView) convertView
.findViewById(R.id.item_icon);// 设置每个条目的图标
holder.item_text = (TextView) convertView
.findViewById(R.id.item_text); // 设置条目的文字说明
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (0 == position) {
holder.item_icon
.setBackgroundResource(android.R.drawable.ic_menu_agenda);
} else if (1 == position) {
holder.item_icon
.setBackgroundResource(android.R.drawable.ic_menu_share);
} else if (2 == position) {
holder.item_icon
.setBackgroundResource(android.R.drawable.ic_menu_manage);
} else if (3 == position) {
holder.item_icon
.setBackgroundResource(android.R.drawable.ic_menu_edit);
} else {
holder.item_icon
.setBackgroundResource(android.R.drawable.ic_menu_close_clear_cancel);
}
holder.item_text.setText(more_list.get(position));
return convertView;
} catch (Exception e) {
Log.e(TAG, "getView error", e);
return null;
}
}
}
已经解决,是我瞎了狗眼 展开
public class ListViewItemAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
try {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.layout_listview_item,
null);
holder.item_icon = (ImageView) convertView
.findViewById(R.id.item_icon);// 设置每个条目的图标
holder.item_text = (TextView) convertView
.findViewById(R.id.item_text); // 设置条目的文字说明
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (0 == position) {
holder.item_icon
.setBackgroundResource(android.R.drawable.ic_menu_agenda);
} else if (1 == position) {
holder.item_icon
.setBackgroundResource(android.R.drawable.ic_menu_share);
} else if (2 == position) {
holder.item_icon
.setBackgroundResource(android.R.drawable.ic_menu_manage);
} else if (3 == position) {
holder.item_icon
.setBackgroundResource(android.R.drawable.ic_menu_edit);
} else {
holder.item_icon
.setBackgroundResource(android.R.drawable.ic_menu_close_clear_cancel);
}
holder.item_text.setText(more_list.get(position));
return convertView;
} catch (Exception e) {
Log.e(TAG, "getView error", e);
return null;
}
}
}
已经解决,是我瞎了狗眼 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询