<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
    主站蜘蛛池模板: 91丁香亚洲综合社区| 免费A级毛片无码A∨男男| 国产亚洲精品观看91在线| 国产成人精品亚洲| 在线日韩av永久免费观看| 99久久婷婷国产综合亚洲| 无码精品A∨在线观看免费| 亚洲今日精彩视频| 国产精品偷伦视频免费观看了| 妞干网在线免费观看| 亚洲熟伦熟女专区hd高清| 91香蕉视频免费| 亚洲人成色777777老人头| 97人伦色伦成人免费视频 | 四虎永久在线精品免费网址| 亚洲欧洲日韩综合| 无码日韩精品一区二区免费 | 亚洲乱码中文字幕在线| 麻豆国产入口在线观看免费 | 亚洲成A人片在线播放器| 精品国产免费观看一区| 色视频在线观看免费| 亚洲区小说区图片区| 一本岛v免费不卡一二三区| 国产免费伦精品一区二区三区| 天天拍拍天天爽免费视频| 久久精品国产亚洲av麻豆蜜芽 | 亚洲精品国产专区91在线| 一区二区三区四区免费视频| 亚洲人成依人成综合网| 99re6免费视频| 亚洲国产精品无码久久久| 2021久久精品免费观看| 亚洲毛片在线观看| 99视频在线免费看| 亚洲午夜国产精品无卡| 妞干网手机免费视频| 男人免费视频一区二区在线观看| 亚洲国产日韩在线观频| 免费无码av片在线观看| 亚洲欧洲自拍拍偷综合|