手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android开发 -- setTag的妙用和The key must be an application-specific resource id 异常
Android开发 -- setTag的妙用和The key must be an application-specific resource id 异常
摘要:tag是view的一个属性,也可以说是view用于存放参数的一个map,对于提高性能和参数传递都有妙用,比如提高listview的性能:用于...

tag是view的一个属性,也可以说是view用于存放参数的一个map,对于提高性能和参数传递都有妙用,比如提高listview的性能:

用于缓存item的view

复制代码 代码如下:public View getView(final int position, View convertView, ViewGroup parent) {

ItemViewHolder holder;

if (convertView == null) {

holder = new ItemViewHolder();

convertView = LayoutInflater.from(context).inflate(R.layout.view_item, null);

holder.timeTextView = (TextView) convertView.findViewById(R.id.text_item_content_time);

holder.remarkTextView = (TextView) convertView.findViewById(R.id.text_item_content_remark);

convertView.setTag(holder);

} else {

holder = (ItemViewHolder)convertView.getTag();

}

if(mMessageListGroup.get(mMessageList.get(position).getGroupId()).isShown()){

convertView.setTag(R.id.child_show, true);

}else{

convertView.setTag(R.id.child_show, false);

}

return convertView;

}

在上面的代码中用到了tag,如果是一个好说直接setTag即可,如果有多个又怎么办呢?

setTag还有一个带int类型的重载,但是设置final类型的常量或者写死数字都会出现:

The key must be an application-specific resource id 异常:

需要在ids.xml文件中定义一个ID,然后设置在这里!!

以上就是Android开发setTag的妙用的全部内容,希望能给大家一个参考,也希望大家多多支持查字典教程网。

【Android开发 -- setTag的妙用和The key must be an application-specific resource id 异常】相关文章:

Android开发笔记 最好使用eclipse

android开发基础教程—SharedPreferences读写

android中图片翻页效果简单的实现方法

Android开发笔记之:复写按钮方法

Android中库项目的使用方法图文介绍

Android开发之SQLite的使用方法

Android 动画之TranslateAnimation应用详解

Android开发笔记之:AsyncTask的应用详解

Android开发之声明周期Activity Lifecycle

Android开发之ContentProvider的使用详解

精品推荐
分类导航