Example usage for android.widget SimpleCursorAdapter SimpleCursorAdapter

List of usage examples for android.widget SimpleCursorAdapter SimpleCursorAdapter

Introduction

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

Prototype

@Deprecated
public SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) 

Source Link

Document

Constructor the enables auto-requery.

Usage

From source file:de.questmaster.fatremote.fragments.SelectFATFragment.java

/**
* Called when the activity is first created. 
* 
* @see android.app.Activity#onCreate(android.os.Bundle) 
 *//*from w w  w  . j a  v a 2 s  .  c  o m*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // enable options menu
    this.setHasOptionsMenu(true);

    // set activity
    c = this.getActivity();

    // set Listener callback
    mListener = (FATSelectedListener) this.getActivity();

    // Init Database
    mDbHelper = new FatDevicesDbAdapter(c);
    try {
        mDbHelper.open();
    } catch (SQLiteException e) {
        Log.e(LOG_TAG, "Database failed to initialize.", e);
    }

    // Create the item list
    Cursor cursor = mDbHelper.fetchAllFatDevices();
    //      getActivity().startManagingCursor(cursor);

    String[] childFrom = new String[] { FatDevicesDbAdapter.KEY_NAME, FatDevicesDbAdapter.KEY_IP };
    int[] childTo = new int[] { R.id.textName, R.id.textIP };

    mListAdapter = new SimpleCursorAdapter(c, R.layout.selectfat_list_item, cursor, childFrom, childTo);
    setListAdapter(mListAdapter);

}

From source file:com.ubuntuone.android.files.fragment.AutoUploadCustomizeFragment.java

private CursorAdapter getWatchedFoldersAdapter() {
    final String[] from = new String[] { WatchedFolders.DISPLAY_NAME };
    final int[] to = new int[] { android.R.id.text1 };

    return new SimpleCursorAdapter(getActivity(), R.layout.list_row_watched_folder, getWatchedFoldersCursor(),
            from, to) {//from w  w w  .ja  v a  2  s  . c om
        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            super.bindView(view, context, cursor);
            AutoUploadCustomizeFragment.this.bindView(view, context, cursor);
        }
    };
}

From source file:whipkey.stemesteem.components.EndingListFragment.java

public void fillData() { // refresh our listview.
    TextView stemText = (TextView) getView().findViewById(R.id.stemTextView);
    stemText.setText(b.getString("stem") + ":");

    c = StemEsteemApplication.getDbHelper().getAllEndings(b.getInt("weekNo"), b.getInt("stemNo"));

    getActivity().startManagingCursor(c);
    String[] from = new String[] { "ending" };
    int[] to = new int[] { R.id.endingListText };

    setListAdapter(new SimpleCursorAdapter(getActivity(), R.layout.endinglist, c, from, to));
}

From source file:com.iskrembilen.quasseldroid.gui.LoginActivity.java

/** Called when the activity is first created. */
@Override//ww w  .  j av a2 s  .  co  m
public void onCreate(Bundle savedInstanceState) {
    setTheme(ThemeUtil.theme);
    super.onCreate(savedInstanceState);
    currentTheme = ThemeUtil.theme;
    setContentView(R.layout.login);

    settings = getSharedPreferences(PREFS_ACCOUNT, MODE_PRIVATE);
    dbHelper = new QuasselDbHelper(this);
    dbHelper.open();

    core = (Spinner) findViewById(R.id.serverSpinner);
    username = (EditText) findViewById(R.id.usernameField);
    password = (EditText) findViewById(R.id.passwordField);
    rememberMe = (CheckBox) findViewById(R.id.remember_me_checkbox);

    //setup the core spinner
    Cursor c = dbHelper.getAllCores();
    startManagingCursor(c);

    String[] from = new String[] { QuasselDbHelper.KEY_NAME };
    int[] to = new int[] { android.R.id.text1 };
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, from,
            to);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //TODO: Ken:Implement view reuse
    core.setAdapter(adapter);

    //Use saved settings
    if (core.getCount() > settings.getInt(PREFS_CORE, 0))
        core.setSelection(settings.getInt(PREFS_CORE, 0));
    username.setText(settings.getString(PREFS_USERNAME, ""));
    password.setText(settings.getString(PREFS_PASSWORD, ""));
    rememberMe.setChecked(settings.getBoolean(PREFS_REMEMBERME, false));

    connect = (Button) findViewById(R.id.connect_button);
    connect.setOnClickListener(onConnect);
}

From source file:com.rightscale.app.dashboard.ShowServerMonitoring.java

public void consumeContent(Cursor cursor, String tag) {
    super.consumeContent(cursor, tag);

    if (tag == MONITORS) {
        _cursor = cursor;/*from  w  ww  .  ja  v a  2s.  c o  m*/
        startManagingCursor(cursor);
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item,
                cursor, FROM, TO);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        Spinner spinner = (Spinner) findViewById(R.id.show_server_monitoring_spinner);
        spinner.setEnabled(true);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                int colHref = _cursor.getColumnIndexOrThrow("href");
                _cursor.moveToPosition(position);
                String href = _cursor.getString(colHref);
                showGraph(href, DEFAULT_SIZE, DEFAULT_PERIOD);
            }

            public void onNothingSelected(AdapterView<?> arg0) {
                //TODO: clear the monitoring graph (fade out, oooh!)
            }
        });
    }
}

From source file:com.schedule.TargetsFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onViewCreated(view, savedInstanceState);

    //initData();
    String[] from = { TargetEntry.COLUMN_NAME };

    int[] to = { android.R.id.text1 };

    mListAdapter = new SimpleCursorAdapter(getActivity(), R.layout.headline_item, null, from, to);
    getLoaderManager().initLoader(TARGET_LOADER, null, this);

    getListView().setLayoutAnimation(// w  w  w. j  a  v a  2  s .  c  om
            AnimationUtils.loadLayoutAnimation(getActivity(), R.anim.layout_bottom_to_top_slide));
    //      
    //      String[]mStrings=new String[]{"a","b","c","d"};
    //      
    //       getListView().setAdapter(new ArrayAdapter<String>(this.getActivity(),
    //                   android.R.layout.simple_list_item_activated_1, mStrings));
    //       
    getListView().setTextFilterEnabled(true);

    // Tell the list view to show one checked/activated item at a time.
    //       getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    // Start with first item activated.
    // Make the newly clicked item the currently selected one.
    getListView().setItemChecked(0, true);
}

From source file:org.sensapp.android.sensappdroid.fragments.GraphsListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setHasOptionsMenu(true);/*from   w w w  .j av  a2  s . c  o m*/
    Cursor cursor = getActivity().getContentResolver().query(SensAppContract.Graph.CONTENT_URI, null, null,
            null, null);
    adapter = new SimpleCursorAdapter(getActivity(), R.layout.graph_simple_row, cursor,
            new String[] { SensAppContract.Graph.TITLE }, new int[] { R.id.graph_name });
    getLoaderManager().initLoader(0, null, this);
    setListAdapter(adapter);
    registerForContextMenu(getListView());
}

From source file:nl.terr.tabweave.TabWeave.java

public void fillData(List<JSONObject> lTabs) {
    // Create an array to specify the fields we want to display in the list (only TITLE)
    String[] from = new String[] { SyncWeave.KEY_TITLE, SyncWeave.KEY_URL, SyncWeave.KEY_ROWID };

    // and an array of the fields we want to bind those fields to (in this case just text1)
    int[] to = new int[] { R.id.title, R.id.url };

    int iBrowserInstances = lTabs.size();
    MatrixCursor matrixCursor = new MatrixCursor(from);

    int iTabId = 0;

    // Show "No tabs" message
    TextView tvNoTabs = (TextView) findViewById(R.id.no_tabs);
    tvNoTabs.setVisibility(View.VISIBLE);

    try {/*  www.  j ava 2  s.  co  m*/
        for (int iWeaveBrowserInstance = 0; iWeaveBrowserInstance < iBrowserInstances; iWeaveBrowserInstance++) {
            int iNumberTabs = lTabs.get(iWeaveBrowserInstance).getJSONArray("tabs").length();

            // Hide "No tabs" message
            if (iNumberTabs > 0) {
                tvNoTabs.setVisibility(View.INVISIBLE);
            }

            for (int iWeaveTab = 0; iWeaveTab < iNumberTabs; iWeaveTab++) {
                matrixCursor.newRow()
                        .add(lTabs.get(iWeaveBrowserInstance).getJSONArray("tabs").getJSONObject(iWeaveTab)
                                .getString("title"))
                        .add(lTabs.get(iWeaveBrowserInstance).getJSONArray("tabs").getJSONObject(iWeaveTab)
                                .getJSONArray("urlHistory").getString(0))
                        .add(iTabId);

                iTabId++;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();

        AlertDialog alert = createAlertDialog(this, e.getClass().toString(), e.getMessage());
        alert.show();
    }

    ListAdapter listAdapter = new SimpleCursorAdapter(this, // Context
            R.layout.tab_row, // Specify the row template to use (here, two columns bound to the two retrieved cursor rows).
            matrixCursor, from, to);

    setListAdapter(listAdapter);
}

From source file:whipkey.stemesteem.main.StemEsteem.java

public void fillData() { // method to reset the adapter with a new cursor
    // when a new week is chosen.

    if (dbHelper.getDatabase().isDbLockedByOtherThreads() == false) {
        Cursor c = dbHelper.getAllStems(currentWeek);
        String[] from = new String[] { "stem" };
        int[] to = new int[] { R.id.stemText };
        startManagingCursor(c);/*from   ww  w.  j a  va2s . com*/
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.stemlist, c, from, to);
        fragList.setAdapter(adapter);

    } else {
        Log.w("DB LOCKED", "Other thread locked database during fillData()");
    }

}

From source file:com.example.android.notepad.NotesList.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_ITEM_INSERT:
        // Launch activity to insert a new item
        startActivity(new Intent(Intent.ACTION_INSERT, getIntent().getData()));
        return true;
    case MENU_ITEM_REFRESH:
        // Ilya: added a refresh button 

        // Perform a managed query. The Activity will handle closing and requerying the cursor
        // when needed.
        Cursor cursor = managedQuery(getIntent().getData(), PROJECTION, null, null, Notes.DEFAULT_SORT_ORDER);

        // Used to map notes entries from the database to views
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.noteslist_item, cursor,
                new String[] { Notes.TITLE }, new int[] { android.R.id.text1 });
        setListAdapter(adapter);// w  w w.j  ava  2  s  . com
        return true;
    }
    return super.onOptionsItemSelected(item);
}