欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android開發(fā) -- setTag的妙用和The key must be an application-specific resource id 異常

 更新時(shí)間:2016年06月03日 11:19:53   作者:封宸落宇  
本文主要介紹Android開發(fā)setTag的妙用,小編覺得挺實(shí)用的,給大家一個(gè)參考,希望對(duì)大家學(xué)習(xí)有所幫助。

tag是view的一個(gè)屬性,也可以說是view用于存放參數(shù)的一個(gè)map,對(duì)于提高性能和參數(shù)傳遞都有妙用,比如提高listview的性能:

用于緩存item的view

復(fù)制代碼 代碼如下:
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,如果是一個(gè)好說直接setTag即可,如果有多個(gè)又怎么辦呢?

setTag還有一個(gè)帶int類型的重載,但是設(shè)置final類型的常量或者寫死數(shù)字都會(huì)出現(xiàn):

The key must be an application-specific resource id 異常

需要在ids.xml文件中定義一個(gè)ID,然后設(shè)置在這里??!

以上就是Android開發(fā)setTag的妙用的全部?jī)?nèi)容,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論