ListView 问题 怎么说呢,就是我通过log发现newView()这个方法执行了好几遍,每次执行这个方法之后,bindView()这个方法就会跟着执行。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public void bindView(View arg0, Context arg1, Cursor arg2) { TextView account = (TextView) (arg0).findViewById(R.id.accountlistlist_account); TextView server = (TextView) (arg0).findViewById(R.id.accountlistlist_server); account.setText(arg2.getString(1)); server.setText(arg2.getString(2)); Log.v("---------------", arg0.toString()+""); Log.v("---------------", arg2.getInt(0)+""); Log.v("---------------", arg2.getInt(1)+""); Log.v("---------------", arg2.getInt(2)+""); Log.v("---------------", "---------------"); if(defaultNum == arg2.getInt(0)) { ImageView iv = (ImageView) (arg0).findViewById(R.id.accountlist_isdefault); iv.setImageResource(R.drawable.fore); } } @Override public View newView(Context arg0, Cursor arg1, ViewGroup arg2) { Log.v("---------------", this.getCount()+""); return mInflater.inflate(R.layout.accountslist, arg2, false); }这是代码 newView这个方法是你的游标有多长久执行几遍,你最好看下源码,newview bingview还有getview这几个方法的相互调用关系,我相信你看完CursorAdapter的源码就会清晰了很多! 一般建议继承自 BaseAdapter因为当你向下滚动的时候,上面的元素则会不可见,然后他会拿来复用,这样会节约内存开销如果有需要可以看看这个代码class delBaseAdapter extends BaseAdapter { private LayoutInflater inflater; private Context context; private ArrayList<HashMap<String, Object>> listItem; class ViewHolder { private TextView location; private CheckBox cb; } public delBaseAdapter() { super(); } public delBaseAdapter(Context context, ArrayList<HashMap<String, Object>> listItem) { this.context = context; this.listItem = listItem; this.inflater = LayoutInflater.from(this.context); del_array = new boolean[listItem.size()]; } public int getCount() { return listItem.size(); } public Object getItem(int position) { return listItem.get(position); } public long getItemId(int position) { return position; } public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { convertView = inflater.inflate(R.layout.del_list_items, null); holder = new ViewHolder(); holder.location = (TextView) convertView.findViewById(R.id.del_location); holder.cb = (CheckBox) convertView.findViewById(R.id.del_checkbox); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.location.setText((String) listItem.get(position).get("del_location")); holder.cb.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { del_array[position] = isChecked; } }); holder.cb.setChecked(del_array[position]); return convertView; } } 对于手势事件里面的onfling()方法,能具体获取到移动了多少距离吗? gridview如何去掉外边框 MediaPlayer 如何实现音乐淡入淡出? android 浏览器打开txt,Doc,xls,ppt HttpURLConnection的问题 高分求助 求教android多点触摸问题 android的WebView打开百度地图的问题 百度云存储 BCS 文件上传,权限设置问题 webapp图标的左右滑动 andriod 开发 android 中如何 link 由 objcopy 生成的文件 超级难的问题,搞了很久也没有找到解决方法
TextView account = (TextView) (arg0).findViewById(R.id.accountlistlist_account);
TextView server = (TextView) (arg0).findViewById(R.id.accountlistlist_server); account.setText(arg2.getString(1));
server.setText(arg2.getString(2));
Log.v("---------------", arg0.toString()+"");
Log.v("---------------", arg2.getInt(0)+"");
Log.v("---------------", arg2.getInt(1)+"");
Log.v("---------------", arg2.getInt(2)+"");
Log.v("---------------", "---------------"); if(defaultNum == arg2.getInt(0)) {
ImageView iv = (ImageView) (arg0).findViewById(R.id.accountlist_isdefault);
iv.setImageResource(R.drawable.fore);
}
} @Override
public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {
Log.v("---------------", this.getCount()+"");
return mInflater.inflate(R.layout.accountslist, arg2, false);
}这是代码
private LayoutInflater inflater; private Context context;
private ArrayList<HashMap<String, Object>> listItem; class ViewHolder {
private TextView location;
private CheckBox cb;
} public delBaseAdapter() {
super();
} public delBaseAdapter(Context context, ArrayList<HashMap<String, Object>> listItem) {
this.context = context;
this.listItem = listItem;
this.inflater = LayoutInflater.from(this.context);
del_array = new boolean[listItem.size()];
} public int getCount() { return listItem.size();
} public Object getItem(int position) {
return listItem.get(position);
} public long getItemId(int position) {
return position;
} public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.del_list_items, null);
holder = new ViewHolder();
holder.location = (TextView) convertView.findViewById(R.id.del_location);
holder.cb = (CheckBox) convertView.findViewById(R.id.del_checkbox);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
} holder.location.setText((String) listItem.get(position).get("del_location"));
holder.cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
del_array[position] = isChecked;
}
});
holder.cb.setChecked(del_array[position]);
return convertView;
} }