<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
    主站蜘蛛池模板: 一区二区三区免费电影| 一级黄色片免费观看| 国产zzjjzzjj视频全免费| 三级片免费观看久久| 亚洲av不卡一区二区三区| 成人免费视频小说| 一级毛片免费在线| 亚洲欧洲日本天天堂在线观看| 在线jyzzjyzz免费视频| a级毛片毛片免费观看永久| 亚洲高清视频在线播放| 免费在线观看亚洲| 亚洲成AV人网址| 亚洲色大成网站www久久九| 国产成人亚洲精品影院| 精品成在人线AV无码免费看| 黄色三级三级三级免费看| 亚洲伦理一区二区| 免费看国产一级片| 国内精品免费麻豆网站91麻豆| eeuss在线兵区免费观看| 亚洲?V无码乱码国产精品 | 精品视频免费在线| 亚洲视频一区在线播放| 亚洲真人日本在线| 精品无码国产污污污免费| 91福利视频免费| 亚洲精品午夜国产VA久久成人| 成熟女人牲交片免费观看视频| 日本免费中文视频| 亚洲三级中文字幕| 亚洲成色999久久网站| 亚洲情侣偷拍精品| 日韩电影免费在线观看视频| 最近免费2019中文字幕大全| 扒开双腿猛进入爽爽免费视频| 国产免费一区二区三区免费视频 | 日韩免费在线中文字幕| 亚洲www77777| 亚洲电影在线免费观看| 亚洲国产三级在线观看|