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:org.sensapp.android.sensappdroid.fragments.SensorListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    Cursor c = adapter.getCursor();
    c.moveToPosition(info.position);
    String sensorName = c.getString(c.getColumnIndexOrThrow(SensAppContract.Sensor.NAME));
    switch (item.getItemId()) {
    case MENU_DELETE_ID:
        new DeleteSensorsTask(getActivity()).execute(sensorName);
        return true;
    case MENU_UPLOAD_ID:
        Intent i = new Intent(getActivity(), SensAppService.class);
        i.setAction(SensAppService.ACTION_UPLOAD);
        i.setData(Uri.parse(SensAppContract.Measure.CONTENT_URI + "/" + sensorName));
        getActivity().startService(i);// w  w w .  j  a  va 2 s .c o m
        return true;
    }
    return super.onContextItemSelected(item);
}

From source file:in.sundar.unitconverter.FormulaeListActivity.java

private void startFormulaEditActivity(long id, int position) {
    // goto the selected formula's edit screen
    Cursor c = formulaeCursor;
    c.moveToPosition(position);
    Intent i = AddModifyFormulaActivity.makeIntent(this, id,
            c.getString(c.getColumnIndexOrThrow(FormulaeDbAdapter.KEY_NAME)),
            c.getString(c.getColumnIndexOrThrow(FormulaeDbAdapter.KEY_INPUT)),
            c.getString(c.getColumnIndexOrThrow(FormulaeDbAdapter.KEY_OUTPUT)),
            c.getString(c.getColumnIndexOrThrow(FormulaeDbAdapter.KEY_FORMULA)));
    startActivityForResult(i, FORMULA_EDIT);
}

From source file:in.sundar.unitconverter.FormulaeListActivity.java

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    // goto the selected formula's screen
    Cursor c = formulaeCursor;
    c.moveToPosition(position);
    Intent i = FormulaUseActivity.makeIntent(this, id,
            c.getString(c.getColumnIndexOrThrow(FormulaeDbAdapter.KEY_NAME)),
            c.getString(c.getColumnIndexOrThrow(FormulaeDbAdapter.KEY_INPUT)),
            c.getString(c.getColumnIndexOrThrow(FormulaeDbAdapter.KEY_OUTPUT)),
            c.getString(c.getColumnIndexOrThrow(FormulaeDbAdapter.KEY_FORMULA)));
    startActivity(i);/*  ww w .j av a  2 s . co  m*/
}

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

public LinkedIdViewFragment getLinkedIdFragment(Uri baseUri, int position, byte[] fingerprint)
        throws IOException {
    Cursor c = getCursor();
    c.moveToPosition(position);
    int rank = c.getInt(UserIdsAdapter.INDEX_RANK);

    Uri dataUri = UserPackets.buildLinkedIdsUri(baseUri);
    return LinkedIdViewFragment.newInstance(dataUri, rank, mIsSecret, fingerprint);
}

From source file:de.aw.monma.views.MonMaAutoCompleteTextView.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Cursor c = (Cursor) parent.getItemAtPosition(position);
    c.moveToPosition(position);
    mLastValidText = c.getString(0);//from www  .  j  a v a  2  s .  co  m
    mLastSelectedID = c.getLong(1);
    if (mOnTextChangeListener != null) {
        mOnTextChangeListener.onTextChanged(this, mLastValidText, mLastSelectedID);
    }
}

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

@Override
public UriAttribute getItem(int position) {
    Cursor cursor = getCursor();
    cursor.moveToPosition(position);
    return getItemAtPosition(cursor);
}

From source file:net.niyonkuru.koodroid.appwidget.WidgetConfigureActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mAppWidgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
            AppWidgetManager.INVALID_APPWIDGET_ID);

    final Intent resultValue = new Intent();
    resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);

    if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
        setResult(RESULT_CANCELED, resultValue);
        finish();/* ww  w.j a v a2 s .  c o m*/
    }

    // Create an empty adapter we will use to display the loaded data.
    mAdapter = new SimpleCursorAdapter(this, android.R.layout.select_dialog_singlechoice, null,
            new String[] { Subscribers.SUBSCRIBER_ID }, new int[] { android.R.id.text1 }, 0);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.choose_subscriber_title);

    builder.setSingleChoiceItems(mAdapter, 0, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int position) {
            final Cursor cursor = mAdapter.getCursor();
            cursor.moveToPosition(position);

            ContentValues values = new ContentValues(1);
            values.put(Settings.SUBSCRIBER, cursor.getString(SubscribersQuery.SUBSCRIBER_ID));

            ContentResolver cr = getContentResolver();
            cr.insert(Settings.buildAppWidgetUri(mAppWidgetId), values);

            mResultCode = RESULT_OK;
            setResult(mResultCode, resultValue);

            dialog.dismiss();
            finish();
        }
    });

    builder.setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            setResult(RESULT_CANCELED, resultValue);

            dialog.dismiss();
            finish();
        }
    });

    builder.setNegativeButton(R.string.cancel, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            dialog.cancel();
        }
    });

    mAlertDialog = builder.create();

    getSupportLoaderManager().initLoader(0, null, this);
}

From source file:com.bangz.smartmute.RulelistFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Cursor cursor = mAdapter.getCursor();
    cursor.moveToPosition(position);
    long rowId = cursor.getLong(cursor.getColumnIndex(RulesColumns._ID));
    int ruletype = cursor.getInt(cursor.getColumnIndex(RulesColumns.RULETYPE));
    //Log.d(TAG,"Param id = " + id + " Get from cursor id = "+ rowId + " Ruletype = " + ruletype);

    mRuleItemSelectedListerner.onRuleItemSelected(id, ruletype);

}

From source file:org.mozilla.search.PreSearchFragment.java

private String getQueryAtPosition(int position) {
    final Cursor c = cursorAdapter.getCursor();
    if (c == null || !c.moveToPosition(position)) {
        return null;
    }//from   w w w. j  a v a2s  .  co  m
    return c.getString(c.getColumnIndexOrThrow(SearchHistory.QUERY));
}

From source file:com.example.asaf.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_my, 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/*from   w  ww  . j a  v  a2  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));
            }
        }
    });

    return rootView;
}