Code example for ImageButton

Methods: setImageDrawablesetVisibility

0
		 
		LayoutParams imageButtonParams = new LayoutParams(buttonParams);
		imageButtonParams.width = 45;
		 
		mButton = new ButtonElement(context);
		mImageButton = new ImageButton(context);
		 
		setButtonText(buttonText);
		super.addView(mButton, buttonParams);
		super.addView(mImageButton, buttonParams);
		 
		// LAYOUT 
		LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		layoutParams.addRule(RelativeLayout.BELOW, mEditText.getId());
		 
		mInnerLayout = new RelativeLayout(context);
		mInnerLayout.setLayoutParams(layoutParams);
		super.addView(mInnerLayout);
		 
		// gives focus to the EditText and shows the keyboard 
		mEditText.requestFocus();
	} 
	 
	public void setOnButtonClickListener(OnClickListener listener) {
		mButton.setOnClickListener(listener);
		mImageButton.setOnClickListener(listener);
	} 
	 
	public void setImeOptions(int opt){
		mEditText.setImeOptions(opt );
	} 
	 
	public void setOnEditorActionListener(OnEditorActionListener onEditorActionListener){
		mEditText.setOnEditorActionListener(onEditorActionListener);
	} 
	 
	 
 
	public void setOnKeyPressedListener(final OnKeyPressedListener listener) {
		mEditText.addTextChangedListener(new TextWatcher() {
			public void afterTextChanged(Editable s) {}
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				listener.onKeyPressed(s.toString());
			} 
		}); 
	} 
	 
	public String getInputText() {
		return mEditText.getText().toString();
	} 
	 
	public void setInputText(String text){
		mEditText.setText(text);
	} 
	 
	public void setCursorAtEnd(){ 
		mEditText.setSelection(mEditText.getText().length());
	} 
	 
	public void setButtonText(String text) {
		if(text==null ) {
			mButton.setVisibility(GONE);
			mImageButton.setVisibility(GONE);
			 
		} else if(text.equals("")){
			mButton.setVisibility(GONE);
			Drawable img = getContext().getResources().getDrawable(mRessource);
			mImageButton.setVisibility(VISIBLE);
			mImageButton.setImageDrawable(img);
		}else{ 
			mButton.setText(text);
			mButton.setVisibility(VISIBLE);
			mImageButton.setVisibility(GONE);
		}