packagecom.yinger;importandroid.content.Context;importandroid.util.AttributeSet;importandroid.view.LayoutInflater;importandroid.view.View;importandroid.widget.Button;importandroid.widget.EditText;importandroid.widget.LinearLayout;publicclassMyClearableEditTextextendsLinearLayout {
EditText editText;
Button clearButton;publicMyClearableEditText(Context context, AttributeSet attrs) {super(context, attrs);//TODO Auto-generated constructor stubinit();
hookupButton();
}publicMyClearableEditText(Context context) {super(context);
init();
hookupButton();
}privatevoidinit() {
String infService=Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li;
li=(LayoutInflater) getContext().getSystemService(infService);
li.inflate(R.layout.clearable_edit_text,this,true);
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));//}privatevoidhookupButton(){
clearButton.setOnClickListener(newButton.OnClickListener(){publicvoidonClick(View v) {//TODO Auto-generated method stubeditText.setText("");
}
});
}
}