Clear listview content?


I have a little problem with ListView. How do I clear a ListView content, knowing that it has a custom adapter?

edit - the custom adapter class extends BaseAdapter, it looks like this:

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {

    private Activity activity;
    private String[] data;
    private static LayoutInflater inflater = null;

    public MyAdapter(Activity a, String[] str) {
        activity = a;
        data = str;
        inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    public static class ViewHolder {
        public TextView text;

    public int getCount() {
        return data.length;

    public Object getItem(int position) {
        return position;

    public long getItemId(int position) {
        return position;

    public View getView(int position, View view, ViewGroup parent) {
        View v = view;
        ViewHolder holder;
        if (v == null) {
            v = inflater.inflate(R.layout.rowa, null);
            holder = new ViewHolder();
            holder.text= v.findViewById(;
        } else {
            holder = v.getTag();


        return v;

1/19/2019 11:26:30 PM

Accepted Answer

Simply write

7/22/2016 10:21:45 AM

I guess you passed a List or an Array to the Adapter. If you keep the instance of this added collection, you can do a


this'll work only if you instantiated the adapter with collection and it's the same instance.

Also, depending on the Adapter you extended, you may not be able to do this. SimpleAdapter is used for static data, thus it can't be updated after creation.

PS. not all Adapters have a clear() method. ArrayAdapter does, but ListAdapter or SimpleAdapter don't

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow