Code example for ImageButton

Methods: setVisibility, getVisibility

0
	private View.OnTouchListener mSearchEditTextOnClickListener = new View.OnTouchListener() {
		 
		@Override 
		public boolean onTouch(View v, MotionEvent event) { 
			if(mSearchCancelButton!= null   
					&& mSearchCancelButton.getVisibility() != View.VISIBLE) 
			{ 
				setSearchBarState(LAYOUT_STATE_EDIT); 
			} 
			return false; 
		} 
	}; 
	 
	/** 搜索条文字变化监听器 ***/ 
	private TextWatcher mSearchTextWatcher = new TextWatcher() {
		 
		@Override 
		public void onTextChanged(CharSequence s, int start, int before, int count) { 
			if(s.toString().length() == 0) { 
				mSearchCancelButton.setVisibility(View.GONE);	 
			} 
			else { 
				mSearchCancelButton.setVisibility(View.VISIBLE); 
			} 
			if(mOnSearchListener != null) 
			{ 
				mOnSearchListener.onSearchChange(s.toString()); 
			}	 
		} 
		@Override 
		public void beforeTextChanged(CharSequence s, int start, int count, 
				int after) { 
		} 
		@Override 
		public void afterTextChanged(Editable s) { 
		} 
	}; 
	 
	/*** 
	 * 设置搜索框是否可以编辑 
	 * @param isEditable 
	 */ 
	private void setTextEditable(boolean isEditable)
	{ 
		if(isEditable)
		{ 
			mSearchEditText.setFocusableInTouchMode(true);
			mSearchEditText.setFocusable(true);
			mSearchEditText.requestFocus();
		} 
		else 
		{ 
			mSearchEditText.clearFocus();
			mSearchEditText.setFocusable(false);
		} 
	} 
	 
	private static final int LAYOUT_STATE_VIEW = 1;
	private static final int LAYOUT_STATE_EDIT = 2;
	/** 
	 * 设置搜索条的状态 
	 * <p>浏览状态 LAYOUT_STATE_VIEW 只显示搜索条 同时失去焦点</p> 
	 * <p>编辑状态 LAYOUT_STATE_EDIT 显示搜索条和取消按钮 获取焦点</p> 
	 * @param state 
	 */ 
	private void setSearchBarState(int state)
	{ 
		switch (state) {
		case LAYOUT_STATE_VIEW:
			 
			mSearchEditText.setText("");
			setTextEditable(false); 
			mSearchCancelButton.setVisibility(View.GONE);			
			 
			break; 
		case LAYOUT_STATE_EDIT:
 
			setTextEditable(true);