介绍我开发过程中用到的一种方法:我们知道当在布局中用到listview的时候,你没有进行优化处理的话,当条目多至如100条左右的时候,项目就会无响应自动挂断,所以我们可以采用在数据适配器中getView方法中复用covertView来减少找到布局的次数。实例代码如下:
class MyAdapter extends BaseAdapter {
@Override
public int getCount() {
// TODO Auto-generated method stub
return mBlackNumberList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return mBlackNumberList.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(final int position, View covertView,
ViewGroup parent) {
View view = null;
if (covertView == null) {
view = View.inflate(getApplicationContext(),
R.layout.listview_blacknumber_item, null);
} else {
view = covertView;
}
TextView tv_phone = (TextView) view
.findViewById(R.id.tv_phonenumber);
TextView tv_mode = (TextView) view.findViewById(R.id.tv_mode);
ImageView iv_delete = (ImageView) view.findViewById(R.id.iv_delete);
共同学习,写下你的评论
评论加载中...
作者其他优质文章