<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 閱讀(965) 評論(0)  編輯  收藏 所屬分類: Android
    主站蜘蛛池模板: 亚洲欧洲日本国产| 亚洲AV无码久久精品蜜桃| 久久狠狠爱亚洲综合影院| 久久国产乱子免费精品| 在线观看国产区亚洲一区成人 | 亚洲一区二区中文| 亚欧免费一级毛片| 亚洲美女自拍视频| 精品成在人线AV无码免费看 | 日韩激情淫片免费看| 亚洲色无码专区一区| 在线观看免费宅男视频| 国产亚洲蜜芽精品久久| 亚洲精品tv久久久久久久久久| 免费一级毛suv好看的国产网站| 久久国产成人精品国产成人亚洲| eeuss影院ss奇兵免费com| 国产精品亚洲аv无码播放| 午夜网站在线观看免费完整高清观看| 在线观看亚洲人成网站| 成视频年人黄网站免费视频| 亚洲日韩国产二区无码| 免费在线观看污网站| CAOPORN国产精品免费视频| 久久精品国产亚洲AV无码偷窥| 黄色成人网站免费无码av| 国产亚洲精品美女2020久久| 日韩va亚洲va欧洲va国产| 18禁美女裸体免费网站| 亚洲AV无码AV日韩AV网站| 奇米影视亚洲春色| 国产成人免费高清激情明星| 亚洲1区2区3区精华液| 国产成人麻豆亚洲综合无码精品| 99热这里只有精品6免费| 亚洲精品无码久久久久牙蜜区| 亚洲七七久久精品中文国产| 91青青青国产在观免费影视| 亚洲精品国产高清在线观看| 亚洲国产另类久久久精品黑人| 9久9久女女免费精品视频在线观看|