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:de.baumann.hhsmoodle.popup.Popup_todo_restart.java

private void setTodoList() {

    NotificationManager nMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nMgr.cancelAll();//  ww w .j  a va  2  s  . c o m

    Schedule_helper.setAlarm(Popup_todo_restart.this);

    Intent serviceIntent = new Intent(Popup_todo_restart.this, class_AlarmService.class);
    startService(serviceIntent);

    //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[] { "todo_title", "todo_content", "todo_creation" };
    final Cursor row = db.fetchAllData(Popup_todo_restart.this);
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(Popup_todo_restart.this, layoutstyle, row, column,
            xml_id, 0) {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));

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

            switch (todo_attachment) {
            case "true":
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.alert_circle);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.alert_circle_red);

                int n = Integer.valueOf(_id);

                android.content.Intent iMain = new android.content.Intent();
                iMain.setAction("shortcutToDo");
                iMain.setClassName(Popup_todo_restart.this, "de.baumann.hhsmoodle.activities.Activity_splash");
                PendingIntent piMain = PendingIntent.getActivity(Popup_todo_restart.this, n, iMain, 0);

                NotificationCompat.Builder builderSummary = new NotificationCompat.Builder(
                        Popup_todo_restart.this).setSmallIcon(R.drawable.school)
                                .setColor(ContextCompat.getColor(Popup_todo_restart.this, R.color.colorPrimary))
                                .setGroup("HHS_Moodle").setGroupSummary(true).setContentIntent(piMain);

                Notification notification = new NotificationCompat.Builder(Popup_todo_restart.this)
                        .setColor(ContextCompat.getColor(Popup_todo_restart.this, R.color.colorPrimary))
                        .setSmallIcon(R.drawable.school).setContentTitle(todo_title)
                        .setContentText(todo_content).setContentIntent(piMain).setAutoCancel(true)
                        .setGroup("HHS_Moodle")
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(todo_content))
                        .setPriority(Notification.PRIORITY_DEFAULT).setVibrate(new long[0]).build();

                NotificationManager notificationManager = (NotificationManager) Popup_todo_restart.this
                        .getSystemService(NOTIFICATION_SERVICE);
                notificationManager.notify(n, notification);
                notificationManager.notify(0, builderSummary.build());
                break;
            }
            return v;
        }
    };

    lv.setAdapter(adapter);
    //onClick function
    try {
        helper_security.encrypt(Popup_todo_restart.this, "/databases/todo_DB_v01.db",
                "/databases/todo_DB_v01_en.db");
    } catch (Exception e) {
        e.printStackTrace();
    }

    new Handler().postDelayed(new Runnable() {
        public void run() {
            finish();
        }
    }, 1000);
}

From source file:com.skubit.satoshidice.DiceAccountView.java

public void initialize(final Activity activity, DrawerLayout drawerLayout) {
    mDrawerLayout = drawerLayout;/* w  ww .  j av  a2  s .  com*/

    mDropdownList = (ListView) findViewById(R.id.account_dropdown);
    final Cursor c = activity.getContentResolver().query(AccountsColumns.CONTENT_URI, null, null, null, null);

    mAdapter = new SimpleCursorAdapter(activity, R.layout.drawer_account_drop_item, c,
            new String[] { AccountsColumns.NICKNAME }, new int[] { R.id.account_name },
            CursorAdapter.FLAG_AUTO_REQUERY);

    final AccountsCursor ac = new AccountsCursor(c);

    mSpinner = findViewById(R.id.account_satoshidice);
    mSpinner.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ImageView expander = (ImageView) mSpinner.findViewById(R.id.expander);

            if (!mDropdownList.isShown()) {
                mDropdownList.setVisibility(View.VISIBLE);
                mDivider.setVisibility(View.VISIBLE);
                expander.setImageResource(R.drawable.ic_action_collapse);
                // TODO: close
            } else {
                mDropdownList.setVisibility(View.GONE);
                expander.setImageResource(R.drawable.ic_action_expand);
                mDivider.setVisibility(View.GONE);
            }

        }
    });

    mExpanderIcon = (ImageView) mSpinner.findViewById(R.id.expander);
    mExpanderIcon.setImageResource(R.drawable.ic_action_expand);
    mDivider = findViewById(R.id.account_divider_bottom);
    mDivider.setVisibility(View.GONE);
    mDropdownList.setAdapter(mAdapter);

    mDropdownList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long arg3) {
            ac.moveToPosition(position);

            ImageView expander = (ImageView) mSpinner.findViewById(R.id.expander);
            expander.setImageResource(R.drawable.ic_action_expand);

            AccountSettings.get(mContext).saveNickName(ac.getNickname());
            AccountSettings.get(mContext).saveSecret(ac.getSecret());
            AccountSettings.get(mContext).saveDepositAddress(ac.getDepositaddress());
            setAccountName();

            Intent intent = new Intent("account_change");
            LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);

            mDivider.setVisibility(View.GONE);
            mDropdownList.setVisibility(View.GONE);
            mDrawerLayout.closeDrawers();
        }
    });
    setAccountName();
}

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

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

    // Intent//ww  w . ja va 2s. c o  m
    final Intent intent = getIntent();

    final long manufacturerId = intent.getLongExtra("id", 0);

    // Layout
    setContentView(R.layout.activity_manufacturer);

    // Get manufacturer
    mSqLiteDatabase = new SlDataSQLiteHelper(mContext).getReadableDatabase();

    String[] manufacturersQueryColumns = { SlDataSQLiteHelper.MANUFACTURERS_COLUMN_NAME };
    mCursor = mSqLiteDatabase.query(SlDataSQLiteHelper.TABLE_MANUFACTURERS, manufacturersQueryColumns,
            SlDataSQLiteHelper.MANUFACTURERS_COLUMN_ID + " = " + manufacturerId, null, null, null, null);

    if (mCursor.moveToFirst()) {
        manufacturerName = mCursor
                .getString(mCursor.getColumnIndexOrThrow(SlDataSQLiteHelper.MANUFACTURERS_COLUMN_NAME));

        String[] medicationsQueryColumns = { SlDataSQLiteHelper.MEDICATIONS_COLUMN_ID,
                SlDataSQLiteHelper.MEDICATIONS_COLUMN_NAME, SlDataSQLiteHelper.MEDICATIONS_COLUMN_SUBSTANCE };
        mCursor = mSqLiteDatabase.query(SlDataSQLiteHelper.TABLE_MEDICATIONS, medicationsQueryColumns,
                SlDataSQLiteHelper.MEDICATIONS_COLUMN_MANUFACTURER + " = " + mTools.sqe(manufacturerName), null,
                null, null, SlDataSQLiteHelper.MEDICATIONS_COLUMN_NAME + " COLLATE NOCASE");

        String[] fromColumns = { SlDataSQLiteHelper.MEDICATIONS_COLUMN_NAME,
                SlDataSQLiteHelper.MEDICATIONS_COLUMN_SUBSTANCE };
        int[] toViews = { R.id.manufacturer_list_item_name, R.id.manufacturer_list_item_substance };

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

        // Toolbar
        final Toolbar toolbar = (Toolbar) findViewById(R.id.manufacturer_toolbar);
        toolbar.setTitle(manufacturerName);

        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        // Medications count
        int medicationsCount = mCursor.getCount();

        String medications = (medicationsCount == 1) ? getString(R.string.manufacturer_medication)
                : getString(R.string.manufacturer_medications);

        TextView medicationsCountTextView = (TextView) findViewById(R.id.manufacturer_medications_count);
        medicationsCountTextView.setText(medicationsCount + " " + medications);

        // List
        ListView listView = (ListView) findViewById(R.id.manufacturer_list);
        listView.setAdapter(simpleCursorAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (mCursor.moveToPosition(i)) {
                    long id = mCursor
                            .getLong(mCursor.getColumnIndexOrThrow(SlDataSQLiteHelper.MEDICATIONS_COLUMN_ID));

                    Intent intent = new Intent(mContext, MedicationActivity.class);

                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        if (mTools.getDefaultSharedPreferencesBoolean("MEDICATION_MULTIPLE_DOCUMENTS"))
                            intent.setFlags(
                                    Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
                    }

                    intent.putExtra("id", id);
                    startActivity(intent);
                }
            }
        });
    }
}

From source file:com.skubit.android.BitIdAccountView.java

public void initialize(final Activity activity, DrawerLayout drawerLayout) {
    mDrawerLayout = drawerLayout;//w ww.j a v  a  2  s  .c  o  m

    mDropdownList = (ListView) findViewById(R.id.account_dropdown);
    final Cursor c = activity.getContentResolver().query(AccountsColumns.CONTENT_URI, null, null, null, null);

    mAdapter = new SimpleCursorAdapter(activity, R.layout.drawer_account_drop_item, c,
            new String[] { AccountsColumns.BITID }, new int[] { R.id.account_name },
            CursorAdapter.FLAG_AUTO_REQUERY);

    final AccountsCursor ac = new AccountsCursor(c);

    mSpinner = findViewById(R.id.account_google);// TODO
    mSpinner.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ImageView expander = (ImageView) mSpinner.findViewById(R.id.expander);

            if (!mDropdownList.isShown()) {
                mDropdownList.setVisibility(View.VISIBLE);
                mDivider.setVisibility(View.VISIBLE);
                expander.setImageResource(R.drawable.ic_action_collapse);
                //TODO: close
            } else {
                mDropdownList.setVisibility(View.GONE);
                expander.setImageResource(R.drawable.ic_action_expand);
                mDivider.setVisibility(View.GONE);
            }

        }
    });

    mExpanderIcon = (ImageView) mSpinner.findViewById(R.id.expander);
    mExpanderIcon.setImageResource(R.drawable.ic_action_expand);
    mDivider = findViewById(R.id.account_divider_bottom);
    mDivider.setVisibility(View.GONE);
    mDropdownList.setAdapter(mAdapter);

    mDropdownList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long arg3) {
            ac.moveToPosition(position);

            ImageView expander = (ImageView) mSpinner.findViewById(R.id.expander);
            expander.setImageResource(R.drawable.ic_action_expand);

            AccountSettings.get(mContext).saveBitIdAccount(ac.getBitid());
            AccountSettings.get(mContext).saveCookie(ac.getCookie());
            AccountSettings.get(mContext).saveBitcoinAddress(null);
            setAccountName();

            //   Intent data = new Intent("signout");
            //   data.putExtra(AccountManager.KEY_ACCOUNT_NAME, ac.getBitid());                      
            //   LocalBroadcastManager.getInstance(mContext).sendBroadcast(data);

            mDivider.setVisibility(View.GONE);
            mDropdownList.setVisibility(View.GONE);
            mDrawerLayout.closeDrawers();
        }
    });
    setAccountName();
}

From source file:de.baumann.hhsmoodle.popup.Popup_note.java

private void setNotesList() {

    //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[] { "note_title", "note_content", "note_creation" };
    final String search = sharedPref.getString("filter_note_subject", "");
    final Cursor row = db.fetchDataByFilter(search, "note_title");

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(Popup_note.this, layoutstyle, row, column, xml_id,
            0) {/*from   ww  w .  jav  a2s  . com*/
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

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

            switch (note_icon) {
            case "3":
                iv_icon.setImageResource(R.drawable.circle_green);
                break;
            case "2":
                iv_icon.setImageResource(R.drawable.circle_yellow);
                break;
            case "1":
                iv_icon.setImageResource(R.drawable.circle_red);
                break;
            }

            switch (note_attachment) {
            case "":
                iv_attachment.setVisibility(View.GONE);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.ic_attachment);
                break;
            }

            File file = new File(note_attachment);
            if (!file.exists()) {
                iv_attachment.setVisibility(View.GONE);
            }

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    final Item[] items = {
                            new Item(getString(R.string.note_priority_0), R.drawable.circle_green),
                            new Item(getString(R.string.note_priority_1), R.drawable.circle_yellow),
                            new Item(getString(R.string.note_priority_2), R.drawable.circle_red), };

                    ListAdapter adapter = new ArrayAdapter<Item>(Popup_note.this,
                            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(Popup_note.this)
                            .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), note_title, note_content, "3",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "2",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "1",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    }
                                }
                            }).show();
                }
            });
            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    helper_main.openAtt(Popup_note.this, lv, note_attachment);
                }
            });
            return v;
        }
    };

    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 _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            final Button attachment2;
            final TextView textInput;

            LayoutInflater inflater = Popup_note.this.getLayoutInflater();

            final ViewGroup nullParent = null;
            final View dialogView = inflater.inflate(R.layout.dialog_note_show, nullParent);

            final String attName = note_attachment.substring(note_attachment.lastIndexOf("/") + 1);
            final String att = getString(R.string.app_att) + ": " + attName;

            attachment2 = (Button) dialogView.findViewById(R.id.button_att);
            if (attName.equals("")) {
                attachment2.setVisibility(View.GONE);
            } else {
                attachment2.setText(att);
            }
            File file2 = new File(note_attachment);
            if (!file2.exists()) {
                attachment2.setVisibility(View.GONE);
            }

            textInput = (TextView) dialogView.findViewById(R.id.note_text_input);
            textInput.setText(note_content);
            Linkify.addLinks(textInput, Linkify.WEB_URLS);

            attachment2.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    helper_main.openAtt(Popup_note.this, lv, note_attachment);
                }
            });

            final ImageView be = (ImageView) dialogView.findViewById(R.id.imageButtonPri);

            switch (note_icon) {
            case "3":
                be.setImageResource(R.drawable.circle_green);
                break;
            case "2":
                be.setImageResource(R.drawable.circle_yellow);
                break;
            case "1":
                be.setImageResource(R.drawable.circle_red);
                break;
            }

            android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(Popup_note.this)
                    .setTitle(note_title).setView(dialogView)
                    .setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setNegativeButton(R.string.note_edit, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            sharedPref.edit().putString("handleTextTitle", note_title)
                                    .putString("handleTextText", note_content)
                                    .putString("handleTextIcon", note_icon).putString("handleTextSeqno", _id)
                                    .putString("handleTextAttachment", note_attachment)
                                    .putString("handleTextCreate", note_creation).apply();
                            helper_main.switchToActivity(Popup_note.this, Activity_EditNote.class, false);
                        }
                    });
            dialog.show();
        }
    });

    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 note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            final CharSequence[] options = { getString(R.string.note_edit), getString(R.string.note_share),
                    getString(R.string.todo_menu), getString(R.string.bookmark_createEvent),
                    getString(R.string.note_remove_note) };
            new AlertDialog.Builder(Popup_note.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.note_edit))) {
                                sharedPref.edit().putString("handleTextTitle", note_title)
                                        .putString("handleTextText", note_content)
                                        .putString("handleTextIcon", note_icon)
                                        .putString("handleTextSeqno", _id)
                                        .putString("handleTextAttachment", note_attachment)
                                        .putString("handleTextCreate", note_creation).apply();
                                helper_main.switchToActivity(Popup_note.this, Activity_EditNote.class, false);
                            }

                            if (options[item].equals(getString(R.string.note_share))) {
                                File attachment = new File(note_attachment);
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("text/plain");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, note_title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, note_content);

                                if (attachment.exists()) {
                                    Uri bmpUri = Uri.fromFile(attachment);
                                    sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
                                }

                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.note_share_2))));
                            }

                            if (options[item].equals(getString(R.string.todo_menu))) {

                                Todo_DbAdapter db = new Todo_DbAdapter(Popup_note.this);
                                db.open();
                                if (db.isExist(note_title)) {
                                    Snackbar.make(lv, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG)
                                            .show();
                                } else {
                                    db.insert(note_title, note_content, "3", "true", helper_main.createDate());
                                    ViewPager viewPager = (ViewPager) Popup_note.this
                                            .findViewById(R.id.viewpager);
                                    viewPager.setCurrentItem(2);
                                    Popup_note.this.setTitle(R.string.todo_title);
                                    dialog.dismiss();
                                }
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                Intent calIntent = new Intent(Intent.ACTION_INSERT);
                                calIntent.setType("vnd.android.cursor.item/event");
                                calIntent.putExtra(CalendarContract.Events.TITLE, note_title);
                                calIntent.putExtra(CalendarContract.Events.DESCRIPTION, note_content);
                                startActivity(calIntent);
                            }

                            if (options[item].equals(getString(R.string.note_remove_note))) {
                                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));
                                                setNotesList();
                                            }
                                        });
                                snackbar.show();
                            }
                        }
                    }).show();

            return true;
        }
    });

    if (lv.getAdapter().getCount() == 0) {
        new android.app.AlertDialog.Builder(this)
                .setMessage(helper_main.textSpannable(getString(R.string.toast_noEntry)))
                .setPositiveButton(this.getString(R.string.toast_yes), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        finish();
                    }
                }).show();
        new Handler().postDelayed(new Runnable() {
            public void run() {
                finish();
            }
        }, 2000);
    }
}

From source file:company.test.Test.java

public void updateUI() {
    SQLiteDatabase sqlDB = helper.getReadableDatabase();
    Cursor cursor = sqlDB.query(ItemContract.TABLE,
            new String[] { ItemContract.Columns._ID, ItemContract.Columns.ITEM }, null, null, null, null, null);
    ListAdapter listAdapter = new SimpleCursorAdapter(this, R.layout.item_view, cursor,
            new String[] { ItemContract.Columns.ITEM }, new int[] { R.id.taskTextView }, 0);
    listView.setAdapter(listAdapter);/* ww  w .  j  a  v a2  s . c  o  m*/
}

From source file:de.baumann.hhsmoodle.popup.Popup_todo.java

private void setTodoList() {

    PreferenceManager.setDefaultValues(Popup_todo.this, R.xml.user_settings, false);
    final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(Popup_todo.this);

    NotificationManager nMgr = (NotificationManager) Popup_todo.this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    nMgr.cancelAll();/*w  w  w  .j  ava 2  s  . c o m*/

    //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[] { "todo_title", "todo_content", "todo_creation" };

    final String search = sharedPref.getString("filter_todo_subject", "");
    final Cursor row = db.fetchDataByFilter(search, "todo_title");
    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(Popup_todo.this, layoutstyle, row, column,
            xml_id, 0) {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

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

            switch (todo_icon) {
            case "3":
                iv_icon.setImageResource(R.drawable.circle_green);
                break;
            case "2":
                iv_icon.setImageResource(R.drawable.circle_yellow);
                break;
            case "1":
                iv_icon.setImageResource(R.drawable.circle_red);
                break;
            }

            switch (todo_attachment) {
            case "true":
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.alert_circle);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.alert_circle_red);

                int n = Integer.valueOf(_id);

                android.content.Intent iMain = new android.content.Intent();
                iMain.setAction("shortcutToDo");
                iMain.setClassName(Popup_todo.this, "de.baumann.hhsmoodle.activities.Activity_splash");
                PendingIntent piMain = PendingIntent.getActivity(Popup_todo.this, n, iMain, 0);

                NotificationCompat.Builder builderSummary = new NotificationCompat.Builder(Popup_todo.this)
                        .setSmallIcon(R.drawable.school)
                        .setColor(ContextCompat.getColor(Popup_todo.this, R.color.colorPrimary))
                        .setGroup("HHS_Moodle").setGroupSummary(true).setContentIntent(piMain);

                Notification notification = new NotificationCompat.Builder(Popup_todo.this)
                        .setColor(ContextCompat.getColor(Popup_todo.this, R.color.colorPrimary))
                        .setSmallIcon(R.drawable.school).setContentTitle(todo_title)
                        .setContentText(todo_content).setContentIntent(piMain).setAutoCancel(true)
                        .setGroup("HHS_Moodle")
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(todo_content))
                        .setPriority(Notification.PRIORITY_DEFAULT).setVibrate(new long[0]).build();

                NotificationManager notificationManager = (NotificationManager) Popup_todo.this
                        .getSystemService(NOTIFICATION_SERVICE);
                notificationManager.notify(n, notification);
                notificationManager.notify(0, builderSummary.build());
                break;
            }

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    final Item[] items = {
                            new Item(getString(R.string.note_priority_0), R.drawable.circle_green),
                            new Item(getString(R.string.note_priority_1), R.drawable.circle_yellow),
                            new Item(getString(R.string.note_priority_2), R.drawable.circle_red), };

                    ListAdapter adapter = new ArrayAdapter<Item>(Popup_todo.this,
                            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(Popup_todo.this)
                            .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), todo_title, todo_content, "3",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), todo_title, todo_content, "2",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), todo_title, todo_content, "1",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    }
                                }
                            }).show();
                }
            });
            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    switch (todo_attachment) {
                    case "true":
                        db.update(Integer.parseInt(_id), todo_title, todo_content, todo_icon, "",
                                todo_creation);
                        setTodoList();
                        break;
                    default:
                        db.update(Integer.parseInt(_id), todo_title, todo_content, todo_icon, "true",
                                todo_creation);
                        setTodoList();
                        break;
                    }
                }
            });
            return v;
        }
    };

    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 _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

            sharedPref.edit().putString("toDo_title", todo_title).apply();
            sharedPref.edit().putString("toDo_text", todo_content).apply();
            sharedPref.edit().putString("toDo_seqno", _id).apply();
            sharedPref.edit().putString("toDo_icon", todo_icon).apply();
            sharedPref.edit().putString("toDo_create", todo_creation).apply();
            sharedPref.edit().putString("toDo_attachment", todo_attachment).apply();

            helper_main.switchToActivity(Popup_todo.this, Activity_todo.class, false);
        }
    });

    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 todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

            final CharSequence[] options = { getString(R.string.bookmark_edit_title),
                    getString(R.string.todo_share), getString(R.string.bookmark_createNote),
                    getString(R.string.bookmark_createEvent), getString(R.string.bookmark_remove_bookmark) };
            new AlertDialog.Builder(Popup_todo.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))) {

                                AlertDialog.Builder builder = new AlertDialog.Builder(Popup_todo.this);
                                View dialogView = View.inflate(Popup_todo.this, 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(todo_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, todo_content,
                                                        todo_icon, todo_attachment, todo_creation);
                                                setTodoList();
                                                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(Popup_todo.this, edit_title);
                            }

                            if (options[item].equals(getString(R.string.todo_share))) {
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("text/plain");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, todo_title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, todo_content);
                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.note_share_2))));
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                Intent calIntent = new Intent(Intent.ACTION_INSERT);
                                calIntent.setType("vnd.android.cursor.item/event");
                                calIntent.putExtra(CalendarContract.Events.TITLE, todo_title);
                                calIntent.putExtra(CalendarContract.Events.DESCRIPTION, todo_content);
                                startActivity(calIntent);
                            }

                            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));
                                                setTodoList();
                                            }
                                        });
                                snackbar.show();
                            }

                            if (options[item].equals(getString(R.string.bookmark_createNote))) {
                                sharedPref.edit().putString("handleTextTitle", todo_title)
                                        .putString("handleTextText", todo_content).apply();
                                helper_main.switchToActivity(Popup_todo.this, Activity_EditNote.class, false);
                            }

                        }
                    }).show();

            return true;
        }
    });

    if (lv.getAdapter().getCount() == 0) {
        new android.app.AlertDialog.Builder(this)
                .setMessage(helper_main.textSpannable(getString(R.string.toast_noEntry)))
                .setPositiveButton(this.getString(R.string.toast_yes), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        finish();
                    }
                }).show();
        new Handler().postDelayed(new Runnable() {
            public void run() {
                finish();
            }
        }, 2000);
    }
}

From source file:com.lewa.crazychapter11.DBTest.java

private void inflateList(Cursor cursor) {
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(DBTest.this, R.layout.db_line, cursor,
            new String[] { "news_title", "news_content" }, new int[] { R.id.my_title, R.id.my_content },
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

    listView.setAdapter(adapter);//from  w  ww.  j a  v  a  2 s .  c  om
    Log.i("DBTest", "inflateList 44444");
}

From source file:org.que.activities.fragments.CalendarBookedFragment.java

@Override
public void onResume() {
    super.onResume();

    //get the date for this tab as given through the args bundle
    Bundle args = new Bundle();
    args.putString("confDayDate", confDayDate);
    //adapter is created with a null pointer, due to cursor not being populated yet. Otherwise the layout
    //is given and ROW_COLUMNS is the data basis and ROW_IDS is the array used to display the data.

    adapter = new SimpleCursorAdapter(getActivity(), R.layout.fragment_agenda_result_row, null, ROW_COLUMNS,
            ROW_IDS, 0);/*from w w w.j  av  a 2  s. c om*/
    adapter.setViewBinder(this);
    setListAdapter(adapter);
    getLoaderManager().initLoader(0, args, this);
    if (index != -1) {
        this.getListView().setSelectionFromTop(index, top);
    }
}

From source file:com.gmail.emerssso.srbase.ListPartsActivity.java

/**
 * Fill data into the ListView from the database.
 *///from  w  w w.j  a v a2  s . com
private void fillData() {
    // Fields from the database (projection)
    // Must include the _id column for the adapter to work
    String[] from = new String[] { PartTable.COLUMN_PART_NUMBER, PartTable.COLUMN_QUANTITY,
            PartTable.COLUMN_SOURCE, PartTable.COLUMN_USED, PartTable.COLUMN_DESCRIPTION, PartTable.COLUMN_ID };
    // Fields on the UI to which we map
    int[] to = new int[] { R.id.part_number_view, R.id.part_quantity_view, R.id.part_source_view,
            R.id.part_used_view, R.id.part_description_view };

    adapter = new SimpleCursorAdapter(this, R.layout.list_part_row, null, from, to, 0);

    setListAdapter(adapter);
    getLoaderManager().initLoader(0, null, this);
}