Android第一行代码(2版)——阅读笔记

1、Android新增的百分比布局
android.support.percent.PercentFrameLayout
在build.gradle下添加依赖包
compile 'com.android.support:percent:22.2.0'
2、LitePal开源数据库框架
3、关于ListView的优化
在Adapter的getView(int position,View convertView,ViewGroup parent)
方法中对于ListView的优化点主要是加载xml文件以及xml文件的组件加载处性能优化。
优化代码如下所示:
判断convertView是否为null,如果为null那么就通过LayoutInflater.from去加载布局文件,如果不为null则不用浪费性能重新加载xml文件,同样通过findViewWithTag或者findViewById的方式获取组件依旧会出现浪费性能的情况,所以这里通过myHolder.textView这样的方式获取组件就会提高ListView的加载性能,经过这两种方式就可以大大的提供ListView的性能了。
public View getView(final int position, View convertView, ViewGroup parent) {
        MyHolder myHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(SDKUtils.getResLayoutId(mContext, "user_item"), null);
            myHolder = new MyHolder();
            myHolder.textView = (TextView) convertView.findViewWithTag("account_textview");
            myHolder.imageView = (ImageView) convertView.findViewWithTag("account_icon");
            myHolder.delButton = (ImageView) convertView.findViewWithTag("account_del");
            convertView.setTag(myHolder);
            convertView.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,
                    SDKUtils.getDimenValue(mContext, "user_item_height")));
            if (currentAccount.getText().toString().equals(list.get(position).getUserName())) {
                myHolder.imageView.setBackgroundResource(SDKUtils.getDrawableId(mContext, "sdk_select_account"));
            } else {
                myHolder.imageView.setBackgroundColor(Color.TRANSPARENT);
            }
        } else {
            myHolder = (MyHolder) convertView.getTag();
        }
        myHolder.textView.setText(list.get(position).getUserName());
        myHolder.delButton.setOnClickListener(new OnClickListener() {


            @Override
            public void onClick(View v) {
                SDKDBManager.getInstance().creatDB(mContext);
                SDKDBManager.getInstance().deleteAccount(list.get(position).getUserName());
                list.remove(position);
                notifyDataSetChanged();
                currentAccount.setText("");
            }
        });
        return convertView;
    }


    class MyHolder {
        public ImageView imageView;
        public TextView textView;
        public ImageView delButton;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值