<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
    主站蜘蛛池模板: 国产精品亚洲片在线观看不卡| 国产偷国产偷亚洲高清日韩| 亚洲精品福利网站| 久久99青青精品免费观看| 亚洲中文字幕无码一久久区| 黄视频在线观看免费| 亚洲欭美日韩颜射在线二| 十八禁在线观看视频播放免费| 国产av天堂亚洲国产av天堂| 免费污视频在线观看| 亚洲精品中文字幕无乱码| 三年片在线观看免费观看高清电影 | 春意影院午夜爽爽爽免费| 四虎影在线永久免费四虎地址8848aa | 亚洲精华液一二三产区| 国产无遮挡又黄又爽免费视频| 大桥未久亚洲无av码在线| 免费国产a国产片高清| 一级做a爰片久久免费| 亚洲AV一宅男色影视| 麻豆视频免费观看| 亚洲成a人片在线观看天堂无码| 免费v片视频在线观看视频| 免费观看四虎精品成人| 亚洲国产精品无码AAA片| 最近中文字幕免费2019| 亚洲欧美精品午睡沙发| 亚洲午夜无码片在线观看影院猛| 爱丫爱丫影院在线观看免费| 亚洲三级在线视频| 亚洲国产婷婷香蕉久久久久久| 最近中文字幕大全免费版在线| 亚洲一区二区三区无码国产| 免费A级毛片无码A| 污污网站免费观看| 亚洲日韩一区精品射精| 亚洲熟妇无码AV在线播放| 免费H网站在线观看的| 免费人成又黄又爽的视频在线电影| 亚洲国产精品SSS在线观看AV| 成年女人毛片免费视频|