Example usage for android.support.v4.widget SimpleCursorAdapter notifyDataSetChanged

List of usage examples for android.support.v4.widget SimpleCursorAdapter notifyDataSetChanged

Introduction

In this page you can find the example usage for android.support.v4.widget SimpleCursorAdapter notifyDataSetChanged.

Prototype

public void notifyDataSetChanged() 

Source Link

Document

Notifies the attached observers that the underlying data has been changed and any View reflecting the data set should refresh itself.

Usage

From source file:com.wheelly.fragments.LocationsListFragment.java

private ListAdapter buildAdapter() {
    if (inSelectMode) {
        return new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_single_choice, null,
                new String[] { "name" }, new int[] { android.R.id.text1 }, 0) {
            {/*from  w  ww  .ja va  2 s  .co m*/
                setViewBinder(new ViewBinder() {
                    @Override
                    public boolean setViewValue(View view, Cursor cursor, int paramInt) {
                        if (android.R.id.text1 == view.getId()) {
                            final String argb = cursor.getString(cursor.getColumnIndex("color"));
                            if (!Strings.isNullOrEmpty(argb)) {
                                view.setBackgroundColor(Color.parseColor(argb));
                            }
                        }
                        return false;
                    }
                });
            }
        };
    }

    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), R.layout.location_item, null,
            new String[] { "name", "resolved_address", "name" },
            new int[] { android.R.id.text1, android.R.id.text2, R.id.text3 }, 0);

    adapter.setViewBinder(new LocationViewBinder(null));

    LocationUtils.obtainLocation(getActivity(), new LocationListener() {
        @Override
        public void onLocationChanged(Location paramLocation) {
            ((LocationViewBinder) adapter.getViewBinder()).location = paramLocation;
            adapter.notifyDataSetChanged();
        }
    });

    return adapter;
}