<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
    主站蜘蛛池模板: 午夜色a大片在线观看免费| 成年大片免费视频| 亚洲高清专区日韩精品| 久香草视频在线观看免费| 四虎永久成人免费| 免费的黄网站男人的天堂| 日本特黄特色aa大片免费| mm1313亚洲国产精品无码试看| 在线播放免费播放av片 | 亚洲熟妇无码AV不卡在线播放| 免费在线观看h片| 7777久久亚洲中文字幕| 成年性午夜免费视频网站不卡| 亚洲日韩一区精品射精| 免费国产精品视频| av午夜福利一片免费看久久| 亚洲性猛交XXXX| 67194成手机免费观看| 亚洲三级视频在线观看| 暖暖免费高清日本中文| 亚洲精品视频免费观看| 亚洲av成人无码久久精品| 亚洲最大免费视频网| 亚洲国产成人精品无码区花野真一| 免费精品一区二区三区在线观看| 色费女人18女人毛片免费视频| jlzzjlzz亚洲乱熟在线播放| 免费观看在线禁片| 2020年亚洲天天爽天天噜| 免费日本黄色网址| 无码人妻精品中文字幕免费 | 91精品免费久久久久久久久| 国产成人精品日本亚洲专一区| 免费在线精品视频| 日本高清免费观看| 亚洲av永久无码精品秋霞电影秋 | 四虎www免费人成| 99在线免费视频| 亚洲小说图区综合在线| 中文字幕在亚洲第一在线 | 成人嫩草影院免费观看|