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

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

Source Link

Document

Standard constructor.

Usage

From source file:org.opendatakit.survey.android.fragments.InstanceUploaderListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    String[] data = new String[] { InstanceColumns.DISPLAY_NAME, InstanceColumns.DISPLAY_SUBTEXT,
            InstanceColumns._ID };/*w w  w.j a  v  a2s .  c om*/
    int[] view = new int[] { R.id.text1, R.id.text2 };

    // render total instance view
    mInstances = new SimpleCursorAdapter(getActivity(), R.layout.upload_multiple_choice, null, data, view, 0);
    setListAdapter(mInstances);

    getLoaderManager().initLoader(INSTANCE_UPLOADER_LIST_LOADER, null, this);
}

From source file:foo.bar.permission2.PermissionActivity.java

private void bindUi() {
    setContentView(R.layout.permission_activity);

    mListView = (ListView) findViewById(R.id.list);
    View emptyView = findViewById(R.id.empty_state);
    mListView.setEmptyView(emptyView);/*from  www  .  java 2  s . com*/

    mContactsAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null,
            CONTACTS_COLUMNS, TO_IDS, 0);

    mEventsAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null, CALENDAR_COLUMNS,
            TO_IDS, 0);
}

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

private void init(Context context, AttributeSet attrs) {
    if (!isInEditMode()) {
        mLoaderManager = ((AppCompatActivity) context).getSupportLoaderManager();
        projection = new String[] { _id, column_accountname };
        selectionNotAusgeblendet = " NOT " + column_ausgeblendet;
        if (mModus == null) {
            TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SpinnerAccount);
            try {
                int modus = a.getInteger(R.styleable.SpinnerAccount_modus, Modus.Cash.ordinal());
                mModus = Modus.values()[modus];
            } finally {
                a.recycle();/* w w w  . j a  v  a  2s.c  o m*/
            }
        }
        int[] adapterRowViews = new int[] { android.R.id.text1 };
        String[] adapterCols = new String[] { column_accountname };
        adapter = new SimpleCursorAdapter(getContext(), android.R.layout.simple_spinner_item, null, adapterCols,
                adapterRowViews, 0);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        setAdapter(adapter);
        super.setOnItemSelectedListener(this);
        if (getVisibility() == VISIBLE) {
            startOrRestartLoader(getId());
        }
    }
}

From source file:de.baumann.browser.popups.Popup_readLater.java

private void setReadLaterList() {

    //display data
    final int layoutstyle = R.layout.list_item;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "readLater_title", "readLater_content", "readLater_creation" };
    final Cursor row = db.fetchAllData(this);
    adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0);

    //display data by filter
    final String note_search = sharedPref.getString("filter_readLaterBY", "readLater_title");
    sharedPref.edit().putString("filter_readLaterBY", "readLater_title").apply();
    editText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }/*from   w  w  w. j  av  a  2 s.c o  m*/

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return db.fetchDataByFilter(constraint.toString(), note_search);
        }
    });

    listView.setAdapter(adapter);
    //onClick function
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            Cursor row = (Cursor) listView.getItemAtPosition(position);
            final String readLater_content = row.getString(row.getColumnIndexOrThrow("readLater_content"));
            sharedPref.edit().putString("openURL", readLater_content).apply();
            finish();
        }
    });

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor row2 = (Cursor) listView.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String readLater_title = row2.getString(row2.getColumnIndexOrThrow("readLater_title"));
            final String readLater_content = row2.getString(row2.getColumnIndexOrThrow("readLater_content"));
            final String readLater_icon = row2.getString(row2.getColumnIndexOrThrow("readLater_icon"));
            final String readLater_attachment = row2
                    .getString(row2.getColumnIndexOrThrow("readLater_attachment"));
            final String readLater_creation = row2.getString(row2.getColumnIndexOrThrow("readLater_creation"));

            final CharSequence[] options = { getString(R.string.menu_share), getString(R.string.menu_save),
                    getString(R.string.bookmark_edit_title), getString(R.string.bookmark_remove_bookmark) };
            new AlertDialog.Builder(Popup_readLater.this)
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.bookmark_edit_title))) {
                                sharedPref.edit().putString("edit_id", _id).apply();
                                sharedPref.edit().putString("edit_content", readLater_content).apply();
                                sharedPref.edit().putString("edit_icon", readLater_icon).apply();
                                sharedPref.edit().putString("edit_attachment", readLater_attachment).apply();
                                sharedPref.edit().putString("edit_creation", readLater_creation).apply();
                                editText.setVisibility(View.VISIBLE);
                                helper_editText.showKeyboard(Popup_readLater.this, editText, 2, readLater_title,
                                        getString(R.string.bookmark_edit_title));
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(listView, R.string.bookmark_remove_confirmation,
                                                Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setReadLaterList();
                                            }
                                        });
                                snackbar.show();
                            }

                            if (options[item].equals(getString(R.string.menu_share))) {
                                final CharSequence[] options = { getString(R.string.menu_share_link),
                                        getString(R.string.menu_share_link_copy) };
                                new AlertDialog.Builder(Popup_readLater.this)
                                        .setPositiveButton(R.string.toast_cancel,
                                                new DialogInterface.OnClickListener() {

                                                    public void onClick(DialogInterface dialog,
                                                            int whichButton) {
                                                        dialog.cancel();
                                                    }
                                                })
                                        .setItems(options, new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int item) {
                                                if (options[item].equals(getString(R.string.menu_share_link))) {
                                                    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                                    sharingIntent.setType("text/plain");
                                                    sharingIntent.putExtra(Intent.EXTRA_SUBJECT,
                                                            readLater_title);
                                                    sharingIntent.putExtra(Intent.EXTRA_TEXT,
                                                            readLater_content);
                                                    startActivity(Intent.createChooser(sharingIntent,
                                                            (getString(R.string.app_share_link))));
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_share_link_copy))) {
                                                    ClipboardManager clipboard = (ClipboardManager) Popup_readLater.this
                                                            .getSystemService(Context.CLIPBOARD_SERVICE);
                                                    clipboard.setPrimaryClip(
                                                            ClipData.newPlainText("text", readLater_content));
                                                    Snackbar.make(listView, R.string.context_linkCopy_toast,
                                                            Snackbar.LENGTH_SHORT).show();
                                                }
                                            }
                                        }).show();
                            }
                            if (options[item].equals(getString(R.string.menu_save))) {
                                final CharSequence[] options = { getString(R.string.menu_save_bookmark),
                                        getString(R.string.menu_save_pass),
                                        getString(R.string.menu_createShortcut) };
                                new AlertDialog.Builder(Popup_readLater.this)
                                        .setPositiveButton(R.string.toast_cancel,
                                                new DialogInterface.OnClickListener() {

                                                    public void onClick(DialogInterface dialog,
                                                            int whichButton) {
                                                        dialog.cancel();
                                                    }
                                                })
                                        .setItems(options, new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int item) {
                                                if (options[item].equals(getString(R.string.menu_save_pass))) {
                                                    helper_editText.editText_savePass(Popup_readLater.this,
                                                            listView, readLater_title, readLater_content);
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_save_bookmark))) {
                                                    DbAdapter_Bookmarks db = new DbAdapter_Bookmarks(
                                                            Popup_readLater.this);
                                                    db.open();

                                                    if (db.isExist(readLater_content)) {
                                                        Snackbar.make(listView,
                                                                getString(R.string.toast_newTitle),
                                                                Snackbar.LENGTH_LONG).show();
                                                    } else {
                                                        db.insert(readLater_title, readLater_content, "", "",
                                                                helper_main.createDate());
                                                        Snackbar.make(listView, R.string.bookmark_added,
                                                                Snackbar.LENGTH_LONG).show();
                                                    }
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_createShortcut))) {
                                                    Intent i = new Intent();
                                                    i.setAction(Intent.ACTION_VIEW);
                                                    i.setClassName(Popup_readLater.this,
                                                            "de.baumann.browser.Browser_left");
                                                    i.setData(Uri.parse(readLater_content));

                                                    Intent shortcut = new Intent();
                                                    shortcut.putExtra("android.intent.extra.shortcut.INTENT",
                                                            i);
                                                    shortcut.putExtra("android.intent.extra.shortcut.NAME",
                                                            "THE NAME OF SHORTCUT TO BE SHOWN");
                                                    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                                                            readLater_content);
                                                    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                                                            Intent.ShortcutIconResource.fromContext(
                                                                    Popup_readLater.this
                                                                            .getApplicationContext(),
                                                                    R.mipmap.ic_launcher));
                                                    shortcut.setAction(
                                                            "com.android.launcher.action.INSTALL_SHORTCUT");
                                                    Popup_readLater.this.sendBroadcast(shortcut);
                                                    Snackbar.make(listView,
                                                            R.string.menu_createShortcut_success,
                                                            Snackbar.LENGTH_SHORT).show();
                                                }
                                            }
                                        }).show();
                            }

                        }
                    }).show();
            return true;
        }
    });

    listView.post(new Runnable() {
        public void run() {
            listView.setSelection(listView.getCount() - 1);
        }
    });
}

From source file:io.github.carlorodriguez.alarmon.MediaListView.java

protected void query(Uri contentUri, String nameColumn, String selection, int rowResId, String[] displayColumns,
        int[] resIDs) {
    this.nameColumn = nameColumn;
    final ArrayList<String> queryColumns = new ArrayList<>(displayColumns.length + 1);
    queryColumns.addAll(Arrays.asList(displayColumns));
    // The ID column is required for the SimpleCursorAdapter.  Make sure to
    // add it if it's not already there.
    if (!queryColumns.contains(BaseColumns._ID)) {
        queryColumns.add(BaseColumns._ID);
    }//  w ww  . j  ava2 s.c  o m

    Cursor dbCursor;

    if (ContextCompat.checkSelfPermission(getContext(),
            Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
        dbCursor = getContext().getContentResolver().query(contentUri,
                queryColumns.toArray(new String[queryColumns.size()]), selection, null, sortOrder);
    } else {
        dbCursor = new MatrixCursor(queryColumns.toArray(new String[queryColumns.size()]));
    }

    if (staticCursor != null) {
        Cursor[] cursors = new Cursor[] { staticCursor, dbCursor };
        cursor = new MergeCursor(cursors);
    } else {
        cursor = dbCursor;
    }
    manageCursor(cursor);

    this.contentUri = contentUri;

    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(getContext(), rowResId, cursor, displayColumns,
            resIDs, 1);
    // Use a custom binder to highlight the selected element.
    adapter.setViewBinder(new ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            if (view.getVisibility() == View.VISIBLE && view instanceof TextView) {
                TextView text = (TextView) view;
                if (isItemChecked(cursor.getPosition())) {
                    text.setTypeface(Typeface.DEFAULT_BOLD);
                } else {
                    text.setTypeface(Typeface.DEFAULT);
                }
            }
            // Let the default binder do the real work.
            return false;
        }
    });
    setAdapter(adapter);
    setOnItemClickListener(this);
}

From source file:net.olejon.mdapp.AtcActivity.java

private void getPharmacologicGroups() {
    mToolbar.setTitle(mPharmacologicGroupsTitle);

    mGroup = "pharmacologic_groups";

    mCursor = mSqLiteDatabase.query(SlDataSQLiteHelper.TABLE_ATC_PHARMACOLOGIC_GROUPS, null,
            SlDataSQLiteHelper.ATC_PHARMACOLOGIC_GROUPS_COLUMN_CODE + " LIKE "
                    + mTools.sqe(mAnatomicalGroupsCode + "%"),
            null, null, null, SlDataSQLiteHelper.ATC_PHARMACOLOGIC_GROUPS_COLUMN_CODE);

    String[] fromColumns = new String[] { SlDataSQLiteHelper.ATC_PHARMACOLOGIC_GROUPS_COLUMN_CODE,
            SlDataSQLiteHelper.ATC_PHARMACOLOGIC_GROUPS_COLUMN_NAME };
    int[] toViews = new int[] { R.id.atc_pharmacologic_groups_list_item_code,
            R.id.atc_pharmacologic_groups_list_item_name };

    SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(mContext,
            R.layout.activity_atc_pharmacologic_groups_list_item, mCursor, fromColumns, toViews, 0);

    mListView.setAdapter(simpleCursorAdapter);

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from   w w w .ja va2  s  . c om
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (mCursor.moveToPosition(i)) {
                mPharmacologicGroupsCode = mCursor.getString(
                        mCursor.getColumnIndexOrThrow(SlDataSQLiteHelper.ATC_PHARMACOLOGIC_GROUPS_COLUMN_CODE));

                mTherapeuticGroupsTitle = mCursor.getString(
                        mCursor.getColumnIndexOrThrow(SlDataSQLiteHelper.ATC_PHARMACOLOGIC_GROUPS_COLUMN_NAME));

                getTherapeuticGroups();
            }
        }
    });
}

From source file:de.baumann.hhsmoodle.data_bookmarks.Bookmarks_Fragment.java

public void setBookmarksList() {

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "bookmarks_title", "bookmarks_content", "bookmarks_creation" };
    final Cursor row = db.fetchAllData(getActivity());
    adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override/*from   w  w w . j  av  a  2  s.c  o m*/
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row = (Cursor) lv.getItemAtPosition(position);
            final String _id = row.getString(row.getColumnIndexOrThrow("_id"));
            final String bookmarks_title = row.getString(row.getColumnIndexOrThrow("bookmarks_title"));
            final String bookmarks_content = row.getString(row.getColumnIndexOrThrow("bookmarks_content"));
            final String bookmarks_icon = row.getString(row.getColumnIndexOrThrow("bookmarks_icon"));
            final String bookmarks_attachment = row
                    .getString(row.getColumnIndexOrThrow("bookmarks_attachment"));
            final String bookmarks_creation = row.getString(row.getColumnIndexOrThrow("bookmarks_creation"));

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            final ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes);

            switch (bookmarks_icon) {
            case "01":
                iv_icon.setImageResource(R.drawable.circle_red);
                break;
            case "02":
                iv_icon.setImageResource(R.drawable.circle_yellow);
                break;
            case "03":
                iv_icon.setImageResource(R.drawable.circle_green);
                break;
            case "04":
                iv_icon.setImageResource(R.drawable.ic_school_grey600_48dp);
                break;
            case "05":
                iv_icon.setImageResource(R.drawable.ic_view_dashboard_grey600_48dp);
                break;
            case "06":
                iv_icon.setImageResource(R.drawable.ic_face_profile_grey600_48dp);
                break;
            case "07":
                iv_icon.setImageResource(R.drawable.ic_calendar_grey600_48dp);
                break;
            case "08":
                iv_icon.setImageResource(R.drawable.ic_chart_areaspline_grey600_48dp);
                break;
            case "09":
                iv_icon.setImageResource(R.drawable.ic_bell_grey600_48dp);
                break;
            case "10":
                iv_icon.setImageResource(R.drawable.ic_settings_grey600_48dp);
                break;
            case "11":
                iv_icon.setImageResource(R.drawable.ic_web_grey600_48dp);
                break;
            case "12":
                iv_icon.setImageResource(R.drawable.ic_magnify_grey600_48dp);
                break;
            case "13":
                iv_icon.setImageResource(R.drawable.ic_pencil_grey600_48dp);
                break;
            case "14":
                iv_icon.setImageResource(R.drawable.ic_check_grey600_48dp);
                break;
            case "15":
                iv_icon.setImageResource(R.drawable.ic_clock_grey600_48dp);
                break;
            case "16":
                iv_icon.setImageResource(R.drawable.ic_bookmark_grey600_48dp);
                break;
            }

            switch (bookmarks_attachment) {
            case "":
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.star_outline);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.star_grey);
                break;
            }

            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    if (bookmarks_attachment.equals("")) {

                        if (db.isExistFav("true")) {
                            Snackbar.make(lv, R.string.bookmark_setFav_not, Snackbar.LENGTH_LONG).show();
                        } else {
                            iv_attachment.setImageResource(R.drawable.star_grey);
                            db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, bookmarks_icon,
                                    "true", bookmarks_creation);
                            setBookmarksList();
                            sharedPref.edit().putString("favoriteURL", bookmarks_content)
                                    .putString("favoriteTitle", bookmarks_title).apply();
                            Snackbar.make(lv, R.string.bookmark_setFav, Snackbar.LENGTH_LONG).show();
                        }
                    } else {
                        iv_attachment.setImageResource(R.drawable.star_outline);
                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, bookmarks_icon, "",
                                bookmarks_creation);
                        setBookmarksList();
                    }
                }
            });

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    final helper_main.Item[] items = {
                            new helper_main.Item(getString(R.string.note_priority_2), R.drawable.circle_red),
                            new helper_main.Item(getString(R.string.note_priority_1), R.drawable.circle_yellow),
                            new helper_main.Item(getString(R.string.note_priority_0), R.drawable.circle_green),
                            new helper_main.Item(getString(R.string.text_tit_11),
                                    R.drawable.ic_school_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_1),
                                    R.drawable.ic_view_dashboard_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_2),
                                    R.drawable.ic_face_profile_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_8),
                                    R.drawable.ic_calendar_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_3),
                                    R.drawable.ic_chart_areaspline_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_4),
                                    R.drawable.ic_bell_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_5),
                                    R.drawable.ic_settings_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_6),
                                    R.drawable.ic_web_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_7),
                                    R.drawable.ic_magnify_grey600_48dp),
                            new helper_main.Item(getString(R.string.title_notes),
                                    R.drawable.ic_pencil_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_9),
                                    R.drawable.ic_check_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_10),
                                    R.drawable.ic_clock_grey600_48dp),
                            new helper_main.Item(getString(R.string.title_bookmarks),
                                    R.drawable.ic_bookmark_grey600_48dp), };

                    ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(),
                            android.R.layout.select_dialog_item, android.R.id.text1, items) {
                        @NonNull
                        public View getView(int position, View convertView, @NonNull ViewGroup parent) {
                            //Use super class to create the View
                            View v = super.getView(position, convertView, parent);
                            TextView tv = (TextView) v.findViewById(android.R.id.text1);
                            tv.setTextSize(18);
                            tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);
                            //Add margin between image and text (support various screen densities)
                            int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f);
                            tv.setCompoundDrawablePadding(dp5);

                            return v;
                        }
                    };

                    new AlertDialog.Builder(getActivity())
                            .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.cancel();
                                }
                            }).setAdapter(adapter, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int item) {
                                    if (item == 0) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "01", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "02", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "03", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 3) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "04", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 4) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "05", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 5) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "06", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 6) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "07", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 7) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "08", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 8) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "09", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 9) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "10", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 10) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "11", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 11) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "12", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 12) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "13", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 13) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "14", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 14) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "15", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 15) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "16", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    }
                                }
                            }).show();
                }
            });
            return v;
        }
    };

    //display data by filter
    final String note_search = sharedPref.getString("filter_bookmarksBY", "bookmarks_title");
    sharedPref.edit().putString("filter_bookmarksBY", "bookmarks_title").apply();
    filter.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return db.fetchDataByFilter(constraint.toString(), note_search);
        }
    });

    lv.setAdapter(adapter);
    //onClick function
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String bookmarks_content = row2.getString(row2.getColumnIndexOrThrow("bookmarks_content"));
            sharedPref.edit().putString("load_next", "true").apply();
            sharedPref.edit().putString("loadURL", bookmarks_content).apply();

            ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager);
            viewPager.setCurrentItem(0);

        }
    });

    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String bookmarks_title = row2.getString(row2.getColumnIndexOrThrow("bookmarks_title"));
            final String bookmarks_content = row2.getString(row2.getColumnIndexOrThrow("bookmarks_content"));
            final String bookmarks_icon = row2.getString(row2.getColumnIndexOrThrow("bookmarks_icon"));
            final String bookmarks_attachment = row2
                    .getString(row2.getColumnIndexOrThrow("bookmarks_attachment"));
            final String bookmarks_creation = row2.getString(row2.getColumnIndexOrThrow("bookmarks_creation"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_menu),
                    getString(R.string.bookmark_createNote), getString(R.string.count_create),
                    getString(R.string.bookmark_createShortcut), getString(R.string.bookmark_createEvent) };
            new AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @SuppressWarnings("ConstantConditions")
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.number_edit_entry))) {

                                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                                View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_title, null);

                                final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
                                edit_title.setHint(R.string.bookmark_edit_title);
                                edit_title.setText(bookmarks_title);

                                builder.setView(dialogView);
                                builder.setTitle(R.string.bookmark_edit_title);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                                String inputTag = edit_title.getText().toString().trim();
                                                db.update(Integer.parseInt(_id), inputTag, bookmarks_content,
                                                        bookmarks_icon, bookmarks_attachment,
                                                        bookmarks_creation);
                                                setBookmarksList();
                                                Snackbar.make(lv, R.string.bookmark_added,
                                                        Snackbar.LENGTH_SHORT).show();
                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

                            if (options[item].equals(getString(R.string.todo_menu))) {
                                Todo_helper.newTodo(getActivity(), bookmarks_title, "", "");
                            }

                            if (options[item].equals(getString(R.string.count_create))) {
                                Count_helper.newCount(getActivity(), bookmarks_title, bookmarks_content,
                                        getActivity().getString(R.string.note_content), false);
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                helper_main.createCalendarEvent(getActivity(), bookmarks_title,
                                        bookmarks_content);
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setBookmarksList();
                                            }
                                        });
                                snackbar.show();
                            }

                            if (options[item].equals(getString(R.string.bookmark_createNote))) {
                                Notes_helper.newNote(getActivity(), bookmarks_title, bookmarks_content, "", "",
                                        "", "");
                            }

                            if (options[item].equals(getString(R.string.bookmark_createShortcut))) {
                                Intent i = new Intent();
                                i.setAction(Intent.ACTION_VIEW);
                                i.setData(Uri.parse(bookmarks_content));

                                Intent shortcut = new Intent();
                                shortcut.putExtra("android.intent.extra.shortcut.INTENT", i);
                                shortcut.putExtra("android.intent.extra.shortcut.NAME",
                                        "THE NAME OF SHORTCUT TO BE SHOWN");
                                shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, bookmarks_title);
                                shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                                        Intent.ShortcutIconResource.fromContext(
                                                getActivity().getApplicationContext(), R.mipmap.ic_launcher));
                                shortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
                                getActivity().sendBroadcast(shortcut);
                                Snackbar.make(lv, R.string.toast_shortcut, Snackbar.LENGTH_LONG).show();
                            }

                        }
                    }).show();

            return true;
        }
    });
}

From source file:com.ultramegasoft.flavordex2.util.EntryFormHelper.java

/**
 * Set up the autocomplete for the maker field.
 *//*  w  w  w .j av  a2 s . co m*/
private void setupMakersAutoComplete() {
    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(mFragment.getContext(),
            R.layout.simple_dropdown_item_2line, null,
            new String[] { Tables.Makers.NAME, Tables.Makers.LOCATION },
            new int[] { android.R.id.text1, android.R.id.text2 }, 0);

    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        @Override
        public Cursor runQuery(CharSequence constraint) {
            final Uri uri;
            if (TextUtils.isEmpty(constraint)) {
                uri = Tables.Makers.CONTENT_URI;
            } else {
                uri = Uri.withAppendedPath(Tables.Makers.CONTENT_FILTER_URI_BASE,
                        Uri.encode(constraint.toString()));
            }

            final Bundle args = new Bundle();
            args.putParcelable("uri", uri);

            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    mFragment.getLoaderManager().restartLoader(LOADER_MAKERS, args, EntryFormHelper.this);
                }
            });

            return adapter.getCursor();
        }
    });

    mTxtMaker.setAdapter(adapter);

    // fill in maker and origin fields with a suggestion
    mTxtMaker.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final Cursor cursor = (Cursor) parent.getItemAtPosition(position);
            cursor.moveToPosition(position);

            final String name = cursor.getString(cursor.getColumnIndex(Tables.Makers.NAME));
            final String origin = cursor.getString(cursor.getColumnIndex(Tables.Makers.LOCATION));
            mTxtMaker.setText(name);
            mTxtOrigin.setText(origin);

            // skip origin field
            mTxtOrigin.focusSearch(View.FOCUS_DOWN).requestFocus();
        }
    });
}

From source file:com.g_node.gca.abstracts.AbstractNotesFragment.java

public void populateListView() {
    Log.i("GCA-Abs-Frag", "in PopulateListview func");
    String getNotesQuery = "SELECT NOTE_ID AS _id, ABSTRACT_UUID, NOTE_TITLE, NOTE_TEXT FROM ABSTRACT_NOTES WHERE ABSTRACT_UUID = '"
            + value + "';";
    notesCursor = DatabaseHelper.database.rawQuery(getNotesQuery, null);
    if (notesCursor.getCount() <= 0) {
        notificationNote.setText("No Notes available for this Abstract");
    } else {/* w  w w  .j a  v a2 s.  c  o m*/
        notificationNote.setText("You have " + notesCursor.getCount() + " Notes for the Abstract");
    }
    notesList = (ListView) getView().findViewById(R.id.noteslist);

    adapter = new SimpleCursorAdapter(getActivity(), R.layout.noteslist_item_layout, notesCursor,
            new String[] { "NOTE_TITLE" }, new int[] { R.id.noteTitle }, 0);
    //adapter.notifyDataSetChanged();
    //ArrayAdapter adapter = new ArrayAdapter<String>(this,  R.layout.noteslist_item_layout, StringArray);
    notesList.setAdapter(adapter);
}

From source file:net.callmeike.android.mojowire.ui.PodcastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
    podcastsView = (ListView) inflater.inflate(R.layout.fragment_podcasts, container, false);

    podcastsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from w  w w  .  j ava 2s  .  co  m*/
        public void onItemClick(AdapterView<?> parent, View view, int p, long id) {
            selectItem(p);
        }
    });

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), R.layout.podcast_row, null, FROM, TO,
            0);
    adapter.setViewBinder(new PodcastBinder());
    podcastsView.setAdapter(adapter);

    getLoaderManager().initLoader(PODCAST_TAG, null, this);

    return podcastsView;
}