title: replacing icon after text changed of editbox in android
body: <p>I have editbox in my application. beside to editbox i have one search icon. whenever user entered any single character i want to replace search icon with one more icon(cross icon) and if user removed all his/her text from editbox again i want search icon. </p>
  
  <p>For this I used below code.</p>
  
  <p>mSearchView.addTextChangedListener(new TextWatcher() {</p>
  
  <pre><code> @Override
        public void onTextChanged(CharSequence searchString, int start, int before, int count) {
              initCloseSearchView();              
              if (mDealerAdapter != null) {
                      mDealerAdapter.getFilter().filter(searchString);
                  }              
  
              }
      @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                      int after) {
  
              }
      @Override
       public void afterTextChanged(Editable s) {
               log.d(TAG, "inside afterTextChanged");
          }
  });
  
  private void initCloseSearchView(){     
    int textLength = mSearchView.length();
    log.d(TAG, "textLength  "+textLength);
    if(textLength &gt;= 1){
      searchIcon.setVisibility(View.GONE);
      View searchView = (View) mLayoutSearch.findViewById(R.id.search);
      ViewGroup parent = (ViewGroup)searchView.getParent();
      int indexOfSearchView = parent.indexOfChild(searchView);
      log.d(TAG, "index of search==&gt;"+indexOfSearchView);
      ImageButton closeSearch = new                       ImageButton(getActivity().getApplicationContext());
      closeSearch.setBackgroundResource(R.drawable.close_search);
      mLayoutSearch.addView(closeSearch, indexOfSearchView);
    }else{
              searchIcon.setVisibility(View.VISIBLE);
          }
  
    }
  </code></pre>
  
  <p>with above code I am able to replace search icon with cross icon but when user delete his/her text from edit box cross icon is appearing more than one time. How to resolve this.</p>
  
  <p>Thanks</p>