android-cursor

Viewpager, Cursor and Fragment

℡╲_俬逩灬. 提交于 2019-12-03 22:46:29
问题 I am new to the viewpager and was wondering if anyone could point me to a tutorial or source code of a project that uses a viewpager with fragments and a database. I've seen examples of PagerAdapters but I'm just not getting how they all work together (Cursor, Fragment and PagerAdapter) Thanks in advance. 回答1: I have posted some answers in the other posts related to your question. Here's some of the links that you might find helpful. First Link: To get custom views in every page slide.

android Cursor to JSONArray

江枫思渺然 提交于 2019-12-03 13:43:30
how can I "convert" a Cursor to a JSONArray? my cursor as 3columns (_id, name, birth) I've searched but I can't not find any examples You can't convert the contents of a cursor directly into a JSONObject, but you can do that with some logic. for eg: retrieve the Strings from the cursor, form a String which follows the JSON format, and use it to make a json object : JSONObject jFromCursor=new JSONObject(string_in_JSON_format); Cursor to JSONArray public JSONArray cur2Json(Cursor cursor) { JSONArray resultSet = new JSONArray(); cursor.moveToFirst(); while (cursor.isAfterLast() == false) { int

AutoCompleteTextView with custom list: how to set up OnItemClickListener

柔情痞子 提交于 2019-12-03 10:16:46
问题 I am working on an app which uses tags. Accessing those should be as simple as possible. Working with an AutoCompleteTextView seems appropriate to me. What I want: existing tags should be displayed in a selectable list with a CheckBox on each item's side existing tags should be displayed UPON FOCUS of AutoCompleteTextView (i.e. not after typing a letter) What I've done so far is storing tags in a dedicated sqlite3 table. Tags are queried resulting in a Cursor. The Cursor is passed to a

How to properly close a cursor in android

穿精又带淫゛_ 提交于 2019-12-03 06:43:25
I have this database using sqlite, and I'm having problem with closing the cursor its saying that Application did not close the cursor or database object that was opened here here's the logcat 10-18 08:40:56.354: E/Cursor(331): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here 10-18 08:40:56.354: E/Cursor(331): at android.database.sqlite.SQLiteCursor.<init>(SQLiteCursor.java:210) 10-18 08:40:56.354: E/Cursor(331): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53) 10-18

Putting cursor data into an array

China☆狼群 提交于 2019-12-03 00:39:03
Being new in Android, I am having trouble dealing with the following: public String[] getContacts(){ Cursor cursor = getReadableDatabase().rawQuery("SELECT name FROM contacts", null); String [] names = {""}; for(int i = 0; i < cursor.getCount(); i ++){ names[i] = cursor.getString(i); } cursor.close(); return names; } The following gives me the following error: 09-18 10:07:38.616: E/AndroidRuntime(28165): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sqllitetrial/com.example.sqllitetrial.InsideDB}: android.database.CursorIndexOutOfBoundsException: Index -1

Cursor index out of bound exception on listview cllick event

*爱你&永不变心* 提交于 2019-12-02 13:13:05
I am performing a sqlite database operation on click event of listview as shown below: ListView lv1 = (ListView) findViewById(R.id.listView1); lv1.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { String out = arg0.getItemAtPosition(arg2).toString(); SQLiteDatabase db = openOrCreateDatabase("mynotedb", MODE_PRIVATE, null); String sql = "select description from notecont where title='"+out+"'"; Cursor c1 = db.rawQuery(sql, null); int n = c1.getColumnIndex("description"); data = c1.getString(n); if(data.equals("")) {

Fetching a large number of contacts

孤街浪徒 提交于 2019-12-01 13:58:22
I'm trying to fetch all the Phone numbers and Emails in Android.by using this code. enter code here String KEY_NAME = "Name"; String KEY_NO = "No"; String selection = ContactsContract.CommonDataKinds.Phone.IN_VISIBLE_GROUP + " = 1"; String sortOrder = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; String data=""; String name=""; ContactEntry contactObj; String id; List<String> temp = new ArrayList<String>(); final String[] projection = new String[]{ContactsContract.Contacts._ID , ContactsContract.Contacts.DISPLAY_NAME , ContactsContract.Contacts.HAS_PHONE

Fetching a large number of contacts

泪湿孤枕 提交于 2019-12-01 12:42:36
问题 I'm trying to fetch all the Phone numbers and Emails in Android.by using this code. enter code here String KEY_NAME = "Name"; String KEY_NO = "No"; String selection = ContactsContract.CommonDataKinds.Phone.IN_VISIBLE_GROUP + " = 1"; String sortOrder = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; String data=""; String name=""; ContactEntry contactObj; String id; List<String> temp = new ArrayList<String>(); final String[] projection = new String[]

Using SimpleCursorAdapter.ViewBinder to change the color of TextView

☆樱花仙子☆ 提交于 2019-12-01 00:03:52
I'm developing an alarm clock app for android and I want to have displayed list of alarms on the main screen. Each row of this ListView is defined in xml file. And I want to have separate TextViews for each day of week. Program will check in sqlite db if for eg. value for monday is = 1 and then change color of this TextView to red. I have written this code, but that doesn't work. What's wrong? private void fillData() { // Get all of the notes from the database and create the item list Cursor c = db.fetchAllAlarms(); startManagingCursor(c); String[] from = new String[] { db.KEY_TIME, db.KEY

Using SimpleCursorAdapter.ViewBinder to change the color of TextView

不问归期 提交于 2019-11-30 19:32:39
问题 I'm developing an alarm clock app for android and I want to have displayed list of alarms on the main screen. Each row of this ListView is defined in xml file. And I want to have separate TextViews for each day of week. Program will check in sqlite db if for eg. value for monday is = 1 and then change color of this TextView to red. I have written this code, but that doesn't work. What's wrong? private void fillData() { // Get all of the notes from the database and create the item list Cursor