title: List View empties after searched item not found and remains empty even after i clear the searched item
body: <p>i have a list view in which i show recent contacts and i have Edittext through which i search my recent list . Everything is perfect when i search but problem arises when the searched item is not found and list becomes empty and remains empty even after i clear my search edit text.</p>
  
  <p>Please tell me where i am making mistake.</p>
  
  <p>Here is my code.</p>
  
  <p><strong>RecentContactAdapter</strong></p>
  
  <pre><code>public class RecentContactsAdapter extends BaseAdapter {
  Context mContext;
  ArrayList&lt;Contacts&gt; coverList;
  public  ArrayList&lt;Contacts&gt; orig;
  private ColorGenerator mColorGenerator = ColorGenerator.MATERIAL;
  private TextDrawable.IBuilder mDrawableBuilder;
  public RecentContactsAdapter(Context c, ArrayList&lt;Contacts&gt; coverList)
  {
      super();
      mContext = c;
      this.coverList = coverList;
      this.orig = new ArrayList&lt;Contacts&gt;();
      this.orig.addAll(coverList);
  
  }
  
  @Override
  public int getCount()
  {
      return coverList.size();
  }
  
  @Override
  public Contacts getItem(int position) {
      return coverList.get(position);
  }
  
  @Override
  public long getItemId(int position) {
      return position;
  }
  
  @Override
  public View getView(final int position, View convertView, final ViewGroup parent)
  {
  
  
  
      return grid;
  }
  
  public void filter(String charText)
  {
      charText = charText.toLowerCase(Locale.getDefault());
      coverList.clear();
      if (charText.length() == 0)
      {
          coverList.addAll(orig);
      }
  
      else
      {
          for (Contacts wp : orig)
          {
              if (wp.getName().toLowerCase(Locale.getDefault())
                      .contains(charText) || wp.getName().toLowerCase(Locale.getDefault())
                      .contains(charText) || wp.getNumber().toLowerCase(Locale.getDefault())
                      .contains(charText))
              {
  
                  if(coverList.contains(wp))
                  {}
                  else {
                      coverList.add(wp);
                  }
              }
          }
      }
      notifyDataSetChanged();
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>RecentContactFragment</strong></p>
  
  <pre><code>public class RecentContactsTab extends Fragment
  {
  View v;
  Context c;
  public static ListView rec_list;
  ArrayList&lt;Contacts&gt; recent_list;
  public static RecentContactsAdapter rec_ContactsAdapter;
  ProgressDialog pd;
  public static String number;
  boolean appInstalled;
  public static String email;
  EditText search;
  Functions functions;
  VariableListener mCallback;
  TextView noContact;
  RecentContactsAdapter search_adapter;
  RelativeLayout list;
  
  
  @Override
  public void onAttach(Context context) {
      try {
          mCallback = (VariableListener) context;
      } catch (ClassCastException e) {
          e.printStackTrace();
      }
      super.onAttach(context);
  }
  
  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
  { Log.e("STEP","1");
      v = inflater.inflate(R.layout.recent_layout, container, false);
      c = this.getActivity();
  
      rec_list = (ListView) v.findViewById(R.id.contact);
      recent_list = new ArrayList&lt;Contacts&gt;();
      search= (EditText) v.findViewById(R.id.recentsearch);
  
      v.findViewById(R.id.searchView1);
      noContact = (TextView) v.findViewById(R.id.rec_noContact);
      list= (RelativeLayout) v.findViewById(R.id.leftSide);
      tabLayout.getSelectedTabPosition();
  
      mCallback.onVariableListener(0);
  
      if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.M)
      {
          new GetCotact().execute();
      } else
          {
          functions = new Functions(c);
          if (Settings.canDrawOverlays(c) &amp;&amp; functions.checkpermission()) {
              new GetCotact().execute();
          } else {
              if (!Settings.canDrawOverlays(c)) {
                  Intent i = new Intent(this.getActivity(), AllPermissions.class);
                  startActivity(i);
              } else if (!functions.checkpermission()) {
                  Intent i = new Intent(this.getActivity(), AllPermissions.class);
                  startActivity(i);
              }
          }
      }
  
     rec_list.setTextFilterEnabled(true);
  
      setupSearchView();
      return v;
  }
  
  private void setupSearchView() {
  
      search.addTextChangedListener(new TextWatcher()
      {
  
          @Override
          public void afterTextChanged(Editable arg0)
          {
              String text = search.getText().toString().toLowerCase(Locale.getDefault());
  
              if (recent_list.size() &gt; 0)
              {
                  rec_ContactsAdapter.filter(text);
              }
  
              else
              {
                      rec_ContactsAdapter = new RecentContactsAdapter(getActivity(), recent_list);
                      rec_list.setAdapter(rec_ContactsAdapter);
  
              }
          }
  
          @Override
          public void beforeTextChanged(CharSequence arg0, int arg1,
                                        int arg2, int arg3)
          {
              search_adapter = new RecentContactsAdapter(getActivity(), recent_list);
              rec_list.setAdapter(rec_ContactsAdapter);
          }
  
          @Override
          public void onTextChanged(CharSequence arg0, int arg1, int arg2,
                                    int arg3) {
              // TODO Auto-generated method stub
          }
      });
  }
  
  class GetCotact extends AsyncTask&lt;String, Void, String&gt; {
  
      @Override
      protected void onPreExecute() {
          Log.e("STEP","2");
          super.onPreExecute();
      }
  
      @Override
      protected void onPostExecute(String s)
      {
          rec_ContactsAdapter = new RecentContactsAdapter(c, recent_list);
          search_adapter=rec_ContactsAdapter;
          rec_list.setAdapter(rec_ContactsAdapter);
          super.onPostExecute(s);
      }
  
      @Override
      protected String doInBackground(String... params) {
          readContacts();
          return null;
  
      }
  }
  
  private void readContacts() {
      ContentResolver cr = getActivity().getContentResolver();
  
      if (ActivityCompat.checkSelfPermission(this.getActivity(), Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED) {
  
      }
      else
      {
          Cursor cur = cr.query(CallLog.Calls.CONTENT_URI, null, null, null, CallLog.Calls._ID + " DESC");
          String phone = null;
          String emailContact = null;
          String image_uri = null;
          Bitmap bitmap;
          String name;
  
  
          if (cur.getCount() &gt; 0)
          {
              while (cur.moveToNext())
              {
                  Log.e("STEP","3");
                  name = cur.getString(cur
                          .getColumnIndex(CallLog.Calls.CACHED_NAME));
                  phone=cur.getString(cur.getColumnIndex(CallLog.Calls.NUMBER));
  
                  if (name==null)
                  {
                      name=" ";
                      phone=cur.getString(cur.getColumnIndex(CallLog.Calls.NUMBER));
  
                      image_uri=null;
                  }
                  else
                  {
                      name = cur.getString(cur
                              .getColumnIndex(CallLog.Calls.CACHED_NAME));
                  }
  
                  recent_list.add(new Contacts(name, phone, image_uri,emailContact));
                  emailContact="";
                  phone="";
              }
              cur.close();
          }
          else
          {
              noContact.setVisibility(View.VISIBLE);
              noContact.setTextColor(getResources().getColor(R.color.default_color));
              noContact.setText("No Recent Contacts");
              list.setVisibility(View.GONE);
              search.setVisibility(View.GONE);
          }
      }
  
  }
  
  @Override
  public void onResume()
  {
      Log.e("STEP","4");
      super.onResume();
  }
  </code></pre>
  
  <p>}</p>