<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    ①自定義復合控件的布局:

    clearable_edit_text.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      
    xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width
    ="fill_parent"
      android:layout_height
    ="fill_parent"
      android:orientation 
    = "horizontal">
      
    <EditText
          
    android:id = "@+id/editText"
          android:layout_width 
    = "200dp"
          android:layout_height 
    = "wrap_content"
          
    />
      
    <Button
          
    android:id = "@+id/clearButton"
          android:layout_width 
    = "100dp"
          android:layout_height 
    = "wrap_content"
          android:text 
    = "Clear"
          
    />
    </LinearLayout>

    很簡單,不廢話

    ②選擇適合放置子控件的布局類,并將其擴展

    package com.yinger;

    import android.content.Context;
    import android.util.AttributeSet;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.LinearLayout;

    public class MyClearableEditText extends LinearLayout {

        EditText editText;
        Button clearButton;

        
    public MyClearableEditText(Context context, AttributeSet attrs) {
            
    super(context, attrs);
            
    // TODO Auto-generated constructor stub
            init();
            hookupButton();
        }

        
    public MyClearableEditText(Context context) {
            
    super(context);
            init();
            hookupButton();
        }

        
    private void init() {
            String infService 
    = Context.LAYOUT_INFLATER_SERVICE;
            LayoutInflater li;
            li 
    = (LayoutInflater) getContext().getSystemService(infService);
            li.inflate(R.layout.clearable_edit_text, 
    thistrue);
            editText 
    = (EditText) findViewById(R.id.editText);
            clearButton 
    = (Button) findViewById(R.id.clearButton);
        }

    //    private void init2() {
    //        setOrientation(LinearLayout.VERTICAL);
    //        editText = new EditText(getContext());
    //        clearButton = new Button(getContext());
    //        clearButton.setText("Clear");
    //        int lHeight = LayoutParams.WRAP_CONTENT;
    //        int lWidth = LayoutParams.FILL_PARENT;
    //        
    //        addView(editText,new LinearLayout.LayoutParams(lWidth,lHeight));
    //        addView(clearButton,new LinearLayout.LayoutParams(lWidth,lHeight));
    //    }
        
        
    private void hookupButton(){
            clearButton.setOnClickListener(
    new Button.OnClickListener(){

                
    public void onClick(View v) {
                    
    // TODO Auto-generated method stub
                    editText.setText("");
                }
            });
        }
    }

    ③引用

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation
    ="vertical"
        android:layout_width
    ="fill_parent"
        android:layout_height
    ="fill_parent"
        
    >
    <TextView  
        
    android:layout_width="fill_parent" 
        android:layout_height
    ="wrap_content" 
        android:text
    ="@string/hello"
        
    />
    <com.yinger.MyClearableEditText
        android:layout_width
    ="fill_parent" 
        android:layout_height
    ="wrap_content" 
    />
    </LinearLayout>



    posted on 2011-06-12 09:53 Ying-er 閱讀(978) 評論(0)  編輯  收藏 所屬分類: Android
    主站蜘蛛池模板: 免费精品国产日韩热久久| 久久嫩草影院免费看夜色| 97久久免费视频| 亚洲理论电影在线观看| 成人免费网站视频www| 人人狠狠综合久久亚洲高清| 亚洲乱理伦片在线观看中字| 亚洲中文无码永久免费| 亚洲精品无播放器在线播放| 午夜视频免费成人| 精品国产亚洲第一区二区三区| 国产精品成人四虎免费视频| 国产99久久亚洲综合精品| 免费一级成人毛片| 精品国产福利尤物免费| 亚洲日本va中文字幕久久| 女同免费毛片在线播放| 亚洲综合精品香蕉久久网97| 亚洲成年人免费网站| 亚洲五月综合缴情婷婷| 四虎免费在线观看| 羞羞漫画在线成人漫画阅读免费| 亚洲精品天堂成人片?V在线播放| 女人隐私秘视频黄www免费| 亚洲高清视频在线观看| 国产99视频精品免费观看7| 亚洲七久久之综合七久久| 亚洲 无码 在线 专区| 三级毛片在线免费观看| 亚洲国产超清无码专区| 蜜臀91精品国产免费观看| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 国产成人亚洲精品青草天美| 中国黄色免费网站| 亚洲成色www久久网站夜月| 四虎成年永久免费网站| 精品国产日韩亚洲一区91| 亚洲AV无码国产精品色午友在线| 免费人成在线观看69式小视频| 中文字幕在线日亚洲9| 亚洲日本一区二区三区在线不卡|