1.layoutinflater.inflate å view.inflate çåºå«
layoutinflater.inflate å view.inflate çåºå«
å¹³æ¶ListViewå è½½itemä¸ï¼adapterçgetViewæ¹æ³ä¸ï¼æ们ç»å¸¸ç¨å°ï¼
LayoutInflater.from(mContext).inflate(R.layout.it,码解注册下载网站源码parent,false);
è¿æ ·çæ¹æ³æ¥å è½½å¸å±xml,å¹³æ¶ä¸ç´å°±æ¯è¿ä¹ç¨çï¼ä¹æ²¡ä»ä¹çé®ãä»å¤©ç½ä¸çäºä¸ªèªå®ä¹å¸å±çæºç ï¼èªå®ä¹å¸å±ä¸å è½½å¸å±xmlç¨çView.inflateæ¹æ³ï¼
public class SettingItemView extends RelativeLayout {
private CheckBox cb_status;
private TextView tv_description;
private TextView tv_title;
private String desc_on;
private String desc_off;
private void iniView(Context context) {
View.inflate(context, R.layout.setting_item_view, this);//第ä¸ä¸ªåæ°ä¼ å¸å±æ件çç¶ç±»
cb_status=(CheckBox) this.findViewById(R.id.cb_status);
tv_description=(TextView) this.findViewById(R.id.tv_description);
tv_title=(TextView) this.findViewById(R.id.tv_title);
}
第ä¸æ¬¡è§ç¨è¿ç§æ¹å¼æ¥å è½½å¸å±çï¼çäºä¸ä»çlistviewå è½½item,ä¹æ¯ç¨è¿ç§æ¹å¼ï¼
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view;
ViewHolder holder;
if(convertView==null){
view=View.inflate(getApplicationContext(), R.layout.list_item_callsms, null);//æåä¸ä¸ªä¼ äºnull
holder=new ViewHolder();
holder.tv_number=(TextView) view.findViewById(R.id.tv_black_number);
holder.tv_mode=(TextView) view.findViewById(R.id.tv_black_mode);
holder.iv_delete=(ImageView) view.findViewById(R.id.iv_delete);
view.setTag(holder);
好å§ï¼çä¸ä¸View.inflateç说æï¼
Open Declaration View android.view.View.inflate(Context context, int resource, ViewGroup root)
Inflate a view from an XML resource. This convenience method wraps the
LayoutInflater class, which provides a full range of options for view
inflation.
Parameters: context The Context object for your activity or
application. resource The resource ID to inflate root A view group
that will be the parent. Used to properly inflate the layout_
*parameters.
See Also: LayoutInflater
æåæä¸å¥è®©ä½ çLayoutInflaterè¿ä¸ªç±»ï¼æçå®å é¨ä¹æ¯ç¨LayoutInflaterå®ç°çï¼è¿å ¥æºç ï¼
public static View inflate(Context context, int resource, ViewGroup root) {
LayoutInflater factory = LayoutInflater.from(context);
return factory.inflate(resource, root);
}
æç¶å é¨ä¹æ¯ç¨LayoutInflaterå®ç°çï¼ä¸ç¥é为å¥androidè¿è¦ç¨View.inflatå°è£ ä¸ä¸ããão(ãââ½âã)o
å ¶ä¸LayoutInflaterçInflateçä¸ä¸ªåæ°ææ为ï¼
对äºInflateçä¸ä¸ªåæ°(int resource, ViewGroup root, boolean attachToRoot)
å¦æinflate(layoutId, null )ålayoutIdçæå¤å±çæ§ä»¶ç宽é«æ¯æ²¡æææç
å¦æinflate(layoutId, root, false ) å认为åä¸é¢æææ¯ä¸æ ·ç
å¦æinflate(layoutId, root, true ) å认为è¿æ ·çè¯layoutIdçæå¤å±æ§ä»¶ç宽é«æè½æ£å¸¸æ¾ç¤º
对è¿ä¸ä¸ªåæ°åºå«ä¸ç解çè¯å¯ä»¥çè¿ç¯æç« ï¼
inflate第ä¸ä¸ªåæ°ææ
ä»æºç è§åº¦è§£æçæé大ç¥çï¼
Android LayoutInflateråçåæï¼å¸¦ä½ ä¸æ¥æ¥æ·±å ¥äºè§£View(ä¸)
以åå¦ä¸ç¯æè§å¾ä¸éçï¼
Android LayoutInflate深度解æ ç»ä½ 带æ¥å ¨æ°ç认è¯
çå®ï¼ä½ åºè¯¥ç¥éè¿ä¸ªåæ°ææäºï¼okï¼åæ¥çä¸é¢ä»£ç ï¼ è¿æ¶å°±å¯ä»¥æ¿æ¢ä¸ºlayoutInflaterçæ¹å¼äºï¼
对äºç¬¬ä¸ä¸ªèªå®ä¹å¸å±ï¼
//View.inflate(context, R.layout.setting_item_view, this);//第ä¸ä¸ªåæ°ä¼ å¸å±æ件çç¶ç±»
LayoutInflater.from(context).inflate(R.layout.setting_item_view, this, true);//çä»·äºä¸é¢
第äºä¸ªéé å¨ä¸getViewï¼
//view=View.inflate(getApplicationContext(), R.layout.list_item_callsms, null);
view=LayoutInflater.from(getApplicationContext()).inflate(R.layout.list_item_callsms,parent,false);
2024-12-29 01:08
2024-12-29 01:04
2024-12-29 00:51
2024-12-29 00:40
2024-12-29 00:35
2024-12-29 00:24
2024-12-28 23:46
2024-12-28 23:05