<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 閱讀(966) 評論(0)  編輯  收藏 所屬分類: Android
    主站蜘蛛池模板: 久久久久亚洲Av无码专| 亚洲精品综合久久| 亚洲av网址在线观看| 三年片免费观看大全国语| 亚洲一区无码精品色| 一个人看的免费高清视频日本| 免费看国产一级特黄aa大片| 美国免费高清一级毛片| 又粗又黄又猛又爽大片免费| 人妻仑乱A级毛片免费看| 亚洲欧洲精品成人久久曰影片| 一个人免费观看视频在线中文| 亚洲中文字幕在线乱码| 免费国产成人午夜在线观看| 久久亚洲精品成人AV| 青春禁区视频在线观看直播免费 | 8090在线观看免费观看| 久久99亚洲网美利坚合众国| 国产免费久久精品99re丫y| 亚洲AV无码一区二区三区牛牛| 免费无码又爽又刺激高潮 | 国产亚洲一区二区在线观看 | 亚洲欧美日韩久久精品| 波多野结衣一区二区免费视频| www一区二区www免费| 亚洲国产精品lv| 久久久久久国产精品免费免费| 久久亚洲AV成人无码国产电影| 狠狠色婷婷狠狠狠亚洲综合| 最近2018中文字幕免费视频| 亚洲乱码国产乱码精华| 亚洲中久无码永久在线观看同| 国产精品色拉拉免费看| 麻豆安全免费网址入口| 亚洲电影中文字幕| 卡一卡二卡三在线入口免费| CAOPORN国产精品免费视频| 亚洲免费闲人蜜桃| 亚洲乱码中文字幕综合234| 中文字幕免费在线| 一级特黄录像免费播放中文版|