Example usage for android.widget SimpleAdapter getFilter

List of usage examples for android.widget SimpleAdapter getFilter

Introduction

In this page you can find the example usage for android.widget SimpleAdapter getFilter.

Prototype

public Filter getFilter() 

Source Link

Usage

From source file:it.uniroma2.foundme.studente.FollowCourseActivity.java

public static void populateView(String[] result) {
    courses = new String[result.length];
    System.arraycopy(result, 0, courses, 0, result.length);
    List<Map<String, String>> data = new ArrayList<Map<String, String>>();

    for (int i = 0; i < result.length; i++) {
        Map<String, String> datum = new HashMap<String, String>(2);
        if (i == 0 && result[0].equalsIgnoreCase(Variables_it.NO_COURSE)) {
            datum.put(Variables_it.COURSE, result[0]);
            datum.put(Variables_it.PROF, "");
            data.add(datum);/*from  w w  w  .j  av  a  2 s . c o m*/
            break;
        } else {
            String[] items = result[i].split(",");
            String ap = items[0] + items[1];
            datum.put(Variables_it.COURSE, ap);
            datum.put(Variables_it.PROF, items[2]);
            data.add(datum);
        }
    }
    //creo l'adapter
    final SimpleAdapter adapter = new SimpleAdapter(context, data, android.R.layout.simple_list_item_2,
            new String[] { Variables_it.COURSE, Variables_it.PROF },
            new int[] { android.R.id.text1, android.R.id.text2 });
    lvTuttiCorsi.setAdapter(adapter);
    lvTuttiCorsi.setTextFilterEnabled(true);

    swipeFollow.setColorSchemeColors(0xff429874, 0xffffffff, 0xff429874, 0xffffffff);
    swipeFollow.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            swipeFollow.setRefreshing(true);
            (new Handler()).postDelayed(new Runnable() {
                @Override
                public void run() {
                    swipeFollow.setRefreshing(false);
                    try {
                        getCourse(false);
                    } catch (ExecutionException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }, 3000);
        }
    });

    lvTuttiCorsi.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!courses[position].equalsIgnoreCase(Variables_it.NO_COURSE))
                alertMessage(courses[position]);
        }
    });

    lvTuttiCorsi.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {

        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
            if (firstVisibleItem == 0)
                swipeFollow.setEnabled(true);
            else
                swipeFollow.setEnabled(false);
        }
    });

    etFilter.addTextChangedListener(new TextWatcher() {

        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
}