Search in a listview
<p>I need help i have a code that someone helped me but its not working because when i search a name thats in the list the list just goes empty and when i erase the list it stays empty. i will post my activity and my adapter</p>

<p>adapter:</p>

<pre><code>public class ClienteSearchListAdapter extends ArrayAdapter&lt;Cliente&gt; {

protected static final String LOG_TAG = ClienteListAdapter.class.getSimpleName();

private List&lt;Cliente&gt; items;
private int layoutResourceId;
private Context context;
private ArrayList&lt;Cliente&gt; arraylist;

public ClienteSearchListAdapter(Context context, int layoutResourceId, List&lt;Cliente&gt; items) {
    super(context, layoutResourceId, items);
    this.layoutResourceId = layoutResourceId;
    this.context = context;
    this.items = items;
    this.arraylist = new ArrayList&lt;Cliente&gt;();
    this.arraylist.addAll(items);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;

    LayoutInflater inflater = ((Activity) context).getLayoutInflater();
    row = inflater.inflate(layoutResourceId, parent, false);

    AtomPaymentHolder holder = new AtomPaymentHolder();
    holder.cliente = items.get(position);
    holder.searchCliente = (ImageButton)row.findViewById(R.id.actionsearch_button);
    holder.searchCliente.setTag(holder.cliente);

    holder.nomecliente = (TextView)row.findViewById(R.id.nomecliente);
    holder.ntele = (TextView)row.findViewById(R.id.ntelecliente);

    row.setTag(holder);

    setupItem(holder);
    return row;
}

private void setupItem(AtomPaymentHolder holder) {
    holder.nomecliente.setText(holder.cliente.getNomeCompleto());
    holder.ntele.setText(String.valueOf(holder.cliente.getNtelemovel()));
}

public static class AtomPaymentHolder {
    Cliente cliente;
    TextView nomecliente;
    TextView ntele;
    ImageButton searchCliente;
}

public void filter(String charText) {
    charText = charText.toLowerCase(Locale.getDefault());
    items.clear();
    if (charText.length() == 0) {
        items.addAll(arraylist);
    }
    else
    {
        for (Cliente wp : arraylist)
        {
            if (wp.getNomeCompleto().toLowerCase(Locale.getDefault()).contains(charText))
            {
                items.add(wp);
            }
        }
    }
    notifyDataSetChanged();
}
}
</code></pre>

<p>activity:</p>

<pre><code>public class search_cli extends BaseNavegationActivity {

private ClienteSearchListAdapter adapter;

List&lt;Cliente&gt; cliente;
EditText editsearch;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_cli);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    editsearch = (EditText) findViewById(R.id.searchname);

    editsearch.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub
            String text = editsearch.getText().toString().toLowerCase(Locale.getDefault());
            adapter.filter(text);
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1,
                                      int arg2, int arg3) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2,
                                  int arg3) {
            // TODO Auto-generated method stub
        }
    });

    ServerRequests serverRequests = new ServerRequests(this);
    serverRequests.FetchClienteDataInBackground(userLocalStore.getLoggedInUser(), new GetContactosCallBack() {
        @Override
        public void done(List&lt;Cliente&gt; returnUser) {
            try {
                if (returnUser == null) {
                    throw new Exception("Não existem dados ou ocorreu um erro no servidor\nTente novamente mais tarde.");

                }
                for (Cliente cliente : returnUser) {
                    adapter.add(cliente);
                }
            }
            catch (Exception erro){
                showError(erro);
            }
        }
    });

    cliente = new ArrayList&lt;&gt;();

    setupListViewAdapter();

}

public void actionOnClickHandler( final View v) {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        try{
            final Cliente itemToaction = (Cliente) v.getTag();


        }
        catch (Exception er)
        {
            showError();
        }
    }
}

private void setupListViewAdapter() {
    adapter = new ClienteSearchListAdapter(search_cli.this, R.layout.clientesearch, cliente);
    ListView atomPaysListView = (ListView)findViewById(R.id.EnterPays_atomPaysList);
    atomPaysListView.setAdapter(adapter);
}

private void showError(Exception ero){
    AlertDialog.Builder dialogBuilder=new AlertDialog.Builder(this);
    dialogBuilder.setMessage("Ocorreu um erro:\n" + ero.getMessage());
    dialogBuilder.setPositiveButton("ok", null);
    dialogBuilder.show();
}

private void showError(){
    android.app.AlertDialog.Builder dialogBuilder=new android.app.AlertDialog.Builder(search_cli.this);
    dialogBuilder.setMessage("Ocorreu um erro, por favor tente novamente mais tarde.");
    dialogBuilder.setPositiveButton("Ok", null);
    dialogBuilder.show();
}
}
</code></pre>

<p>layout of the activity:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".search_cli"
android:id="@+id/search_cli_container"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"&gt;
&lt;EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/searchname"
    android:layout_marginTop="10dp"
    android:hint="Pesquisar"/&gt;

&lt;ListView
    android:id="@+id/EnterPays_atomPaysList"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    tools:listitem="@layout/clientesearch"
    android:layout_below="@+id/layout_search_cli" &gt;
&lt;/ListView&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>My layout for the list view contains an image button and two labels with nome and ntelemovel.</p>