title: Search View not Searching ListView
body: <p>I am Trying to Display the Contact From Phone to the <code>ListView</code>(Which is used in a <code>Fragment</code>)..... I have Tried Putting a <code>SearchView</code> to Filter Data from <code>ListView</code>.....</p>
  
  <p><strong>Search View Does Not Filter Data ....</strong></p>
  
  <p>Pls Help ...I Am badly Stuck...</p>
  
  <p>ScreenShot of App having <code>SearchView</code> over List View Showing Contact Details....</p>
  
  <p><a href="https://drive.google.com/file/d/0B8sFN35Zdhnfa0RtVEJKc2V2WG8/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/0B8sFN35Zdhnfa0RtVEJKc2V2WG8/view?usp=sharing</a></p>
  
  <p><a href="https://drive.google.com/file/d/0B8sFN35ZdhnfWTljaTRWaGY3c1E/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/0B8sFN35ZdhnfWTljaTRWaGY3c1E/view?usp=sharing</a></p>
  
  <p>contactfragment.xml , GetContactAdapter.java , <strong>Contact_Fragment3.java</strong></p>
  
  <p>are three different files..</p>
  
  <pre><code>**contractfragment.xml**
  
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
  
  
      &lt;SearchView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/searchContactLIST"
          android:queryHint="Search...."
          android:clickable="true"
          &gt;
      &lt;/SearchView&gt;
  
      &lt;ListView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:id="@+id/lists"
          android:scrollbarStyle="outsideOverlay"
          /&gt;
  &lt;/LinearLayout&gt;
  
  
  
  
  
   **GetContactAdapter.java**
  
  package com.example.cosmic.zumi_test;
  
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.BaseAdapter;
  import android.widget.Filter;
  import android.widget.Filterable;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  import java.util.ArrayList;
  import java.util.List;
  
  
  public class GetContactAdapter extends ArrayAdapter&lt;String&gt; implements Filterable {
  
  
      String[] phone = {};
      String[] names = {};
      int[] img = {};
      Context c;
      LayoutInflater inflater;
  
      public class Viewholder {
          TextView names;
          TextView address;
          ImageView img;
      }
  
      public GetContactAdapter(Context context, String[] names, String[] add) {
  
          super(context, R.layout.customcontactlist, names);
  
          this.c = context;
          this.names = names;
          this.phone = add;
          this.img = img;
  
  
      }
  
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
  
          if (convertView == null) {
              inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = inflater.inflate(R.layout.customcontactlist, null);
  
          }
          Viewholder viewholder = new Viewholder();
  
          viewholder.names = (TextView) convertView.findViewById(R.id.contact_name);
  
          viewholder.address = (TextView) convertView.findViewById(R.id.contact_no);
  
  
          viewholder.img = (ImageView) convertView.findViewById(R.id.image_contactlist);
  
  //ASSIGN DATA
          viewholder.img.setImageResource(R.drawable.com_facebook_button_icon_blue);
          viewholder.names.setText(names[position]);
          viewholder.address.setText(phone[position]);
  
          return convertView;
  
      }
  
  
  }
  **Contact_Fragment3.java**
  
  
  
   package com.example.cosmic.zumi_test;
  
      import android.Manifest;
      import android.content.ContentResolver;
      import android.content.ContentUris;
      import android.content.Intent;
      import android.content.pm.PackageManager;
      import android.database.Cursor;
      import android.graphics.Bitmap;
      import android.net.Uri;
      import android.os.Build;
      import android.os.Bundle;
      import android.provider.ContactsContract;
      import android.support.annotation.Nullable;
      import android.support.v4.app.Fragment;
      import android.support.v4.content.ContextCompat;
      import android.support.v4.view.MenuItemCompat;
      import android.support.v7.app.AppCompatActivity;
      import android.support.v7.widget.SearchView;
      import android.text.TextUtils;
      import android.view.LayoutInflater;
      import android.view.Menu;
      import android.view.MenuInflater;
      import android.view.MenuItem;
      import android.view.View;
      import android.view.ViewGroup;
      import android.widget.ArrayAdapter;
      import android.widget.Filterable;
      import android.widget.ListView;
      import android.widget.Toast;
  
      import java.io.InputStream;
      import java.lang.reflect.Array;
      import java.util.ArrayList;
      import java.util.List;
  
      /**
       * Created by cosmic on 31/12/16.
       */
      public class Contact_FRAGMENT3 extends Fragment {
  
  
          private Uri uriContact;
          private String contactID;
          private ListView lstNames;
          private GetContactAdapter adapter;
          // Request code for READ_CONTACTS. It can be any number &gt; 0.
          private static final int PERMISSIONS_REQUEST_READ_CONTACTS = 100;
  
          private android.widget.SearchView search;
  
          @Nullable
          @Override
          public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  
              View v = inflater.inflate(R.layout.contactfragment, container, false);
  
              this.lstNames = (ListView) v.findViewById(R.id.lists);
              this.search = (android.widget.SearchView) v.findViewById(R.id.searchContactLIST);
  
  
              // Read and show the contacts
              showContacts();
  
  
              return v;
  
          }
  
  
          private void showContacts() {
              // Check the SDK version and whether the permission is already granted or not.
              if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M &amp;&amp; ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
                  requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, PERMISSIONS_REQUEST_READ_CONTACTS);
                  //After this point you wait for callback in onRequestPermissionsResult(int, String[], int[]) overriden method
              } else {
                  // Android version is lesser than 6.0 or the permission is already granted.
  
  
                  List&lt;String&gt; contacts = getContactNames();
                  //  String[] arr_contact=contacts.to
                  List&lt;String&gt; contacts_no = getContactNo();
  
  
                  String[] strarray = new String[contacts.size()];
                  contacts.toArray(strarray);
  
  
                  String[] strarray2 = new String[contacts_no.size()];
                  contacts_no.toArray(strarray2);
  
  
                  adapter = new GetContactAdapter(getContext(), strarray, strarray2);
  
                  lstNames.setAdapter(adapter);
  
  
                  search.setOnQueryTextListener(new android.widget.SearchView.OnQueryTextListener() {
                      @Override
                      public boolean onQueryTextSubmit(String query) {
                          return false;
                      }
  
                      @Override
                      public boolean onQueryTextChange(String newText) {
  
                          adapter.getFilter().filter(newText);
                          return true;
  
                      }
                  });
  
  
              }
          }
  
          @Override
          public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
              if (requestCode == PERMISSIONS_REQUEST_READ_CONTACTS) {
                  if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                      // Permission is granted
                      showContacts();
                  } else {
                      Toast.makeText(getContext(), "Until you grant the permission, we cannot display the names", Toast.LENGTH_SHORT).show();
                  }
              }
          }
  
  
          private List&lt;String&gt; getContactNames() {
              List&lt;String&gt; contacts = new ArrayList&lt;&gt;();
  
              List&lt;String&gt; number = new ArrayList&lt;&gt;();
              // Get the ContentResolver
              ContentResolver cr = getActivity().getContentResolver();
              // Get the Cursor of all the contacts
              Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
  
              // Move the cursor to first. Also check whether the cursor is empty or not.
              if (cursor.moveToFirst()) {
                  // Iterate through the cursor
                  do {
                      // Get the contacts name
                      String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                      String numbers = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
  
                      number.add(numbers);
                      contacts.add(name);
                  } while (cursor.moveToNext());
              }
              // Close the curosor
              cursor.close();
  
              return contacts;
          }
  
  
          private List&lt;String&gt; getContactNo() {
  
              List&lt;String&gt; number = new ArrayList&lt;&gt;();
              // Get the ContentResolver
              ContentResolver cr = getActivity().getContentResolver();
              // Get the Cursor of all the contacts
              Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
  
              // Move the cursor to first. Also check whether the cursor is empty or not.
              if (cursor.moveToFirst()) {
                  // Iterate through the cursor
                  do {
                      // Get the contacts name
                      //  String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                      String numbers = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
  
                      number.add(numbers);
                      // contacts.add(name);
                  } while (cursor.moveToNext());
              }
              // Close the curosor
              cursor.close();
  
              return number;
  
          }
  
  
      }
  </code></pre>