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

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

Introduction

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

Prototype

public ViewBinder getViewBinder() 

Source Link

Document

Returns the ViewBinder used to bind data to views.

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) {
            {/*  w  ww  .j a v a  2s.  com*/
                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;
}