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

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

Introduction

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

Prototype

public Cursor getCursor() 

Source Link

Document

Returns the cursor.

Usage

From source file:can.yrt.onebusaway.MyRouteListFragmentBase.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {

    // Get the cursor and fetch the stop ID from that.
    SimpleCursorAdapter cursorAdapter = (SimpleCursorAdapter) l.getAdapter();
    Cursor c = cursorAdapter.getCursor();
    c.moveToPosition(position - l.getHeaderViewsCount());
    final String routeId = c.getString(COL_ID);
    final String routeName = c.getString(COL_SHORTNAME);

    if (isShortcutMode()) {
        final Intent shortcut = UIHelp.makeShortcut(getActivity(), routeName,
                RouteInfoActivity.makeIntent(getActivity(), routeId));

        Activity activity = getActivity();
        activity.setResult(Activity.RESULT_OK, shortcut);
        activity.finish();//from  www .  ja  v  a2  s.  c o m

    } else {
        RouteInfoActivity.start(getActivity(), routeId);
    }
}

From source file:org.onebusaway.android.ui.MyRouteListFragmentBase.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {

    // Get the cursor and fetch the route ID from that.
    SimpleCursorAdapter cursorAdapter = (SimpleCursorAdapter) l.getAdapter();
    Cursor c = cursorAdapter.getCursor();
    c.moveToPosition(position - l.getHeaderViewsCount());
    final String routeId = c.getString(COL_ID);
    final String routeName = c.getString(COL_SHORTNAME);

    if (isShortcutMode()) {
        final Intent shortcut = UIUtils.makeShortcut(getActivity(), routeName,
                RouteInfoActivity.makeIntent(getActivity(), routeId));

        Activity activity = getActivity();
        activity.setResult(Activity.RESULT_OK, shortcut);
        activity.finish();/*ww w  .  j  a  v  a 2  s  .c  o m*/

    } else {
        RouteInfoActivity.start(getActivity(), routeId);
    }
}

From source file:can.yrt.onebusaway.MyStopListFragmentBase.java

private void showOnMap(ListView l, int position) {
    // Get the cursor and fetch the stop ID from that.
    SimpleCursorAdapter cursorAdapter = (SimpleCursorAdapter) l.getAdapter();
    Cursor c = cursorAdapter.getCursor();
    c.moveToPosition(position - l.getHeaderViewsCount());
    final String stopId = c.getString(COL_ID);
    final double lat = c.getDouble(COL_LATITUDE);
    final double lon = c.getDouble(COL_LONGITUDE);

    HomeActivity.start(getActivity(), stopId, lat, lon);
}

From source file:can.yrt.onebusaway.MyStopListFragmentBase.java

protected StopData getStopData(ListView l, int position) {
    // Get the cursor and fetch the stop ID from that.
    SimpleCursorAdapter cursorAdapter = (SimpleCursorAdapter) l.getAdapter();
    return new StopData(cursorAdapter.getCursor(), position - l.getHeaderViewsCount());
}

From source file:org.onebusaway.android.ui.MyRemindersFragment.java

private String[] getIds(ListView l, int position) {
    // Get the cursor and fetch the stop ID from that.
    SimpleCursorAdapter cursorAdapter = (SimpleCursorAdapter) l.getAdapter();
    final Cursor c = cursorAdapter.getCursor();
    c.moveToPosition(position - l.getHeaderViewsCount());
    final String[] result = new String[] { c.getString(COL_ID), c.getString(COL_STOP_ID),
            c.getString(COL_ROUTE_ID) };
    return result;
}

From source file:com.josenaves.sunshine.app.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // The SimpleCursorAdapter will take data from the database through the
    // Loader and use it to populate the ListView it's attached to.
    mForecastAdapter = new SimpleCursorAdapter(getActivity(), R.layout.list_item_forecast, null,
            // the column names to use to fill the textviews
            new String[] { WeatherContract.WeatherEntry.COLUMN_DATETEXT,
                    WeatherContract.WeatherEntry.COLUMN_SHORT_DESC,
                    WeatherContract.WeatherEntry.COLUMN_MAX_TEMP,
                    WeatherContract.WeatherEntry.COLUMN_MIN_TEMP },
            // the textviews to fill with the data pulled from the columns above
            new int[] { R.id.list_item_date_textview, R.id.list_item_forecast_textview,
                    R.id.list_item_high_textview, R.id.list_item_low_textview },
            0);// ww  w  . j a  v  a  2 s . c  o m

    mForecastAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            boolean isMetric = Utility.isMetric(getActivity());
            switch (columnIndex) {
            case COL_WEATHER_MAX_TEMP:
            case COL_WEATHER_MIN_TEMP: {
                // we have to do some formatting and possibly a conversion
                ((TextView) view).setText(Utility.formatTemperature(cursor.getDouble(columnIndex), isMetric));
                return true;
            }
            case COL_WEATHER_DATE: {
                String dateString = cursor.getString(columnIndex);
                TextView dateView = (TextView) view;
                dateView.setText(Utility.formatDate(dateString));
                return true;
            }
            }
            return false;
        }
    });

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
    listView.setAdapter(mForecastAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            SimpleCursorAdapter adapter = (SimpleCursorAdapter) adapterView.getAdapter();
            Cursor cursor = adapter.getCursor();
            if (cursor != null && cursor.moveToPosition(position)) {
                String dateString = Utility.formatDate(cursor.getString(COL_WEATHER_DATE));
                String weatherDescription = cursor.getString(COL_WEATHER_DESC);

                boolean isMetric = Utility.isMetric(getActivity());
                String high = Utility.formatTemperature(cursor.getDouble(COL_WEATHER_MAX_TEMP), isMetric);
                String low = Utility.formatTemperature(cursor.getDouble(COL_WEATHER_MIN_TEMP), isMetric);

                String detailString = String.format("%s - %s - %s/%s", dateString, weatherDescription, high,
                        low);

                Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT,
                        detailString);
                startActivity(intent);
            }
        }
    });

    return rootView;
}