Example usage for android.database Cursor moveToPosition

List of usage examples for android.database Cursor moveToPosition

Introduction

In this page you can find the example usage for android.database Cursor moveToPosition.

Prototype

boolean moveToPosition(int position);

Source Link

Document

Move the cursor to an absolute position.

Usage

From source file:com.nadmm.airports.afd.BrowseAirportsFragment.java

@Override
protected void onListItemClick(ListView l, View v, int position) {
    position = mAdapter.sectionedPositionToPosition(position);
    CursorAdapter adapter = (CursorAdapter) getListAdapter();
    Cursor c = adapter.getCursor();
    c.moveToPosition(position);
    if (mMode == BROWSE_STATE_MODE) {
        mMode = BROWSE_AIRPORTS_MODE;/*  w  w  w  . ja  v  a2  s  . c  o m*/
        mListState = getListView().onSaveInstanceState();
        setListShown(false);
        getListView().setAdapter(null);
        mStateCode = c.getString(c.getColumnIndex(DatabaseManager.Airports.ASSOC_STATE));
        mStateName = c.getString(c.getColumnIndex(DatabaseManager.States.STATE_NAME));
        setBackgroundTask(new BrowseAirportsTask()).execute(mStateCode, mStateName);
    } else {
        String siteNumber = c.getString(c.getColumnIndex(DatabaseManager.Airports.SITE_NUMBER));
        Intent intent = new Intent(getActivity(), AirportActivity.class);
        intent.putExtra(DatabaseManager.Airports.SITE_NUMBER, siteNumber);
        startActivity(intent);
    }
}

From source file:tom.udacity.sample.sunrise.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // The SimpleCursorAdapter will take data from the database through the
    // Loader and use it to populate the ListView it's attached to.
    mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);

    mListView = (ListView) rootView.findViewById(R.id.listview_forecast);
    mListView.setAdapter(mForecastAdapter);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/* www .j  av a2 s.  com*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mPosition = position;
            Cursor cursor = mForecastAdapter.getCursor();
            if (cursor != null && cursor.moveToPosition(position)) {
                ((Callback) getActivity()).onItemSelected(cursor.getString(COL_WEATHER_DATE));
            }
        }
    });

    if (savedInstanceState != null && savedInstanceState.containsKey(POSITION_ARG)) {
        mPosition = savedInstanceState.getInt(POSITION_ARG);
    }

    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
}

From source file:com.demo.weather.sunshine.ForecastFragment.java

private void openPreferredLocationInMap() {
    // Using the URI scheme for showing a location found on a map.  This super-handy
    // intent can is detailed in the "Common Intents" page of Android's developer site:
    // http://developer.android.com/guide/components/intents-common.html#Maps
    if (null != mForecastAdapter) {
        Cursor c = mForecastAdapter.getCursor();
        if (c != null) {
            c.moveToPosition(0);
            String posLat = c.getString(COL_COORD_LAT);
            String posLong = c.getString(COL_COORD_LONG);
            Uri geoLocation = Uri.parse("geo:" + posLat + "," + posLong);

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(geoLocation);

            if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
                startActivity(intent);/*from w  w w.jav  a2  s  . c o m*/
            } else {
                Log.d(LOG_TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!");
            }
        }
    }
}

From source file:com.sonaive.v2ex.ui.FeedsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.list_fragment_layout, container, false);
    mRecyclerView = (FlexibleRecyclerView) root.findViewById(R.id.recycler_view);
    if (UIUtils.isTablet(getActivity())) {
        mLayoutManager = new StaggeredGridLayoutManager(getResources().getInteger(R.integer.feeds_columns),
                StaggeredGridLayoutManager.VERTICAL);
    } else {/*from   w  w  w .  j  a v  a  2s.c  om*/
        mLayoutManager = new LinearLayoutManager(getActivity());
    }
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.addOnItemTouchListener(
            new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    Cursor cursor = mAdapter.getCursor();
                    if (cursor != null && cursor.moveToPosition(position)) {
                        Intent intent = new Intent(getActivity(), FeedDetailActivity.class);
                        Bundle bundle = new Bundle();
                        Parcelable feed = cursor2Parcelable(cursor);
                        bundle.putParcelable("feed", feed);
                        intent.putExtra("bundle", bundle);
                        startActivity(intent);
                    }
                }
            }));
    mEmptyView = (TextView) root.findViewById(android.R.id.empty);
    return root;
}

From source file:com.aafr.alfonso.sunshine.app.ForecastFragment.java

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

    // The ArrayAdapter will take data from a source and
    // use it to populate the ListView it's attached to.
    mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);

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

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

        @Override/*from  w  ww.  j  ava 2  s. c om*/
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Cursor cursor = mForecastAdapter.getCursor();
            if (cursor != null && cursor.moveToPosition(position)) {
                ((Callback) getActivity()).onItemSelected(cursor.getString(COL_WEATHER_DATE));
            }
            mPosition = position;
        }
    });

    // If there's instance state, mine it for useful information.
    // The end-goal here is that the user never knows that turning their device sideways
    // does crazy lifecycle related things.  It should feel like some stuff stretched out,
    // or magically appeared to take advantage of room, but data or place in the app was never
    // actually *lost*.
    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        // The listview probably hasn't even been populated yet.  Actually perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
}

From source file:com.example.android.spotifystreamer.app.spotifystreamerFragment.java

private void openPreferredLocationInMap() {
    // Using the URI scheme for showing a location found on a map.  This super-handy
    // intent can is detailed in the "Common Intents" page of Android's developer site:
    // http://developer.android.com/guide/components/intents-common.html#Maps
    if (null != mspotifystreamerAdapter) {
        Cursor c = mspotifystreamerAdapter.getCursor();
        if (null != c) {
            c.moveToPosition(0);
            String posLat = c.getString(COL_COORD_LAT);
            String posLong = c.getString(COL_COORD_LONG);
            Uri geoLocation = Uri.parse("geo:" + posLat + "," + posLong);

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(geoLocation);

            if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
                startActivity(intent);//ww  w . ja  v  a2 s  .  c  o  m
            } else {
                Log.d(LOG_TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!");
            }
        }

    }
}

From source file:com.demo.weather.sunshine.ForecastFragment.java

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

    // The ArrayAdapter will take data from a source and
    // use it to populate the ListView it's attached to.
    mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);

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

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

        @Override/* w w w  . ja  v a  2 s  .c o m*/
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Cursor cursor = mForecastAdapter.getCursor();
            if (cursor != null && cursor.moveToPosition(position)) {
                ((Callback) getActivity()).onItemSelected(cursor.getString(COL_WEATHER_DATE));
            }
            mPosition = position;
        }
    });

    // If there's instance state, mine it for useful information.
    // The end-goal here is that the user never knows that turning their device sideways
    // does crazy lifecycle related things.  It should feel like some stuff stretched out,
    // or magically appeared to take advantage of room, but data or place in the app was never
    // actually *lost*.
    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        // The listview probably hasn't even been populated yet.  Actually perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    return rootView;
}

From source file:org.sufficientlysecure.keychain.ui.adapter.KeyAdapter.java

@Override
public KeyItem getItem(int position) {
    Cursor c = getCursor();
    if (c.isClosed() || !c.moveToPosition(position)) {
        return null;
    }/* w w  w.  j av  a  2  s  .co  m*/
    return new KeyItem(c);
}

From source file:com.example.tony.popularmovie.MainActivityFragment.java

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

    mMoviePosterAdapter = new MoviePosterAdapter(getActivity(), null, 0);

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

    GridView gridview = (GridView) rootView.findViewById(R.id.gridview);
    gridview.setAdapter(mMoviePosterAdapter);

    gridview.setOnItemClickListener(new OnItemClickListener() {
        @Override/*from w w  w .  j ava2s .co  m*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Cursor cursor = (Cursor) parent.getItemAtPosition(position);
            String movieId = null;
            if (cursor.moveToPosition(position)) {
                movieId = cursor.getString(cursor.getColumnIndex(MovieContract.PopularEntry.COLUMN_MOVIE_ID));
            }

            ((Callback) getActivity()).onItemSelected(movieId);
        }
    });

    return rootView;
}

From source file:com.cse.rajat.sunshine.app.ForecastFragment.java

private void openPreferredLocationInMap() {
    // Using the URI scheme for showing a location found on a map.  This super-handy
    // intent can is detailed in the "Common Intents" page of Android's developer site:
    // http://developer.android.com/guide/components/intents-common.html#Maps
    if (null != mForecastAdapter) {
        Cursor c = mForecastAdapter.getCursor();
        if (null != c) {
            c.moveToPosition(0);
            String posLat = c.getString(COL_COORD_LAT);
            String posLong = c.getString(COL_COORD_LONG);
            Uri geoLocation = Uri.parse("geo:" + posLat + "," + posLong);

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(geoLocation);

            Log.d(LOG_TAG, "Location" + geoLocation.toString());

            if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
                startActivity(intent);//from  ww w. ja v a2s  . c  o m
            } else {
                Log.d(LOG_TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!");
            }
        }

    }
}