FAQ Database Discussion Community


Cursor in sqlite remaining in -1 position

android,sqlite,android-cursor
I am coding for an android app, i have 3 columns in my database, i have put values into the database using a cursor and i want to retrieve those and display it. But while retrieving it i am getting an exception i.e. CursorIndexOutofBounds Exception, index -1 requested with a...

Using Custom Adapter with CursorLoader

android,baseadapter,custom-adapter,android-cursor,android-cursorloader
I'm trying to use CursorLoader to fetch data from my ContentProvider off the UI thread. I then use it to populate my list view. I was using SimpleCursorAdapter before and it works all fine. But now I want to have different views for the list view rows depending upon the...

Get Contact No From PhoneBook In android

android,android-activity,android-contacts,android-logcat,android-cursor
I'm developing a simple app, in which, when I click on EditText, phone contact will open and when user select a contact, it will be displayed in EditText. I have done it, but the problem is for some contact it display output like this: 05-09 13:39:03.660: D/Actual No--->>>(953): 84 85...

SQLite Database Update Needs Application to ReOpen to Actually Show New Values

android,sql,sqlite,sql-update,android-cursor
public void updateRow(int form_no, String form_name, String question_name, String answer_1, String answer_2, String answer_3, int answer_1_count, int answer_2_count, int answer_3_count) { String sql = "UPDATE " + DATABASE_TABLE + " SET " + KEY_ANSWER_1_COUNT + " = " + answer_1_count + ", " +KEY_ANSWER_2_COUNT + " = " + answer_2_count...

Getting invalid column data1?

android,android-cursor
I'm trying to get user image, contact name and contact number but getting exception invalid column data1 error. Here is my code : public interface ContactsQuery { // An identifier for the loader final static int QUERY_ID = 1; // A content URI for the Contacts table final static Uri...

How to store current locale date and time in SQLite

android,sqlite,date,android-cursor
..and later retrieve and show them as Strings? I'm asking the user some input and I want to store both the date (i.e., day, month and year) and the time (i.e., the hour of the day) this input was submitted. Each submission is then saved in my SQlite database, and...

How to use android SQLite cursors to show a row in the table

android,sqlite,android-cursor
Don't ask questions here often but I have a MyDBHelper class with a method 'databaseToString' which I'm pretty sure is wrong but what I want to do is get the details that the user enters in the form which are stored in the 'details' table and output them in a...

Using SQLite cusor to output table contents in listview in a fragment

android,android-cursor
Here I have MyDBHandler with a getAllDetails method that queries the database using a cursor and returns a list. What I don't know what to do now is how to output this list in a listview in another fragment. I was told to create two xml layouts and a custom...

Unable to identify WhatsApp contacts

android,android-contacts,whatsapp,android-cursor,rawcontactid
I'm trying to write an Android program which can identify if a given contact number is associated with WhatsApp or not. I managed to find out if a particular contact name has WhatsApp account or not. How can I find out which contact corresponding to that contact name has WhatsApp?...

Create sqlite database through android

java,android,database,sqlite,android-cursor
I believe with the following code, I am able to create a database, create a table, and insert the sensor values inside. This line create a db -> super(context, "sensor.sqlite", null, 1); in data/data/example.com.sensor/databases/sensor.sqlite In the oncreate method, a table is created. In the insert method, a record will be...

Set specific edittext has cursor blinking when enter the page

android,android-layout,android-edittext,android-cursor
The problem is there is a edittext and I would like to set it default has a cursor on it (but not focus and hide the keyboard ) try android:textCursorDrawable="@null" android:cursorVisible="true" <EditText android:id="@+id/comment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="1dp" android:background="@drawable/comment" android:hint="@string/cmt" android:paddingLeft="5dp" android:paddingRight="5dp" android:textColor="#AAACAD" android:textColorHint="#AAACAD"...

how to store value from cursor into string in android

android,android-intent,android-contacts,android-cursor
I'm creating application that can retrieve contact name from number. While Googling, I got this block of code from this post: Getting contact name from number in Android 2.3.4 public static String getContactName(String num, ContentResolver cr) { Uri u = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI Uri.encode(num)); String[] projection = new String[] { ContactsContract.Contacts.DISPLAY_NAME}; Cursor...

Can't get items from ListAdapter

android,sqlite,listview,android-cursor
I read data from database: private MyDatabase db; private Cursor cities; private ListAdapter cityListAdapter; private ListView citiesListView; db = new MyDatabase(getContext()); cities = db.getCities(); And set an adapter for it: cityListAdapter = new SimpleCursorAdapter(getContext(), android.R.layout.simple_list_item_1, cities, new String[] {"city"}, new int[] {android.R.id.text1},0); citiesListView.setAdapter(cityListAdapter); I can see the ListView populated correctly....

Large data from SQLite on ListView

android,sqlite,android-listview,listadapter,android-cursor
If CursorAdapter is deprecated, what's the recommended way to manage large data in a ListView? After API level 11 there's LoaderManager. But apparently you need to use it together with CursorAdapter? Is there a newer way?...

SQLiteDatabase Cursor empty only on Android 5.0+ devices

android,android-sqlite,android-cursor
The application has a SearchView which fetches suggestions from a specific database table. Everything worked without any errors until Android 5.0 appeared. As of then, when the SQLiteQueryBuilder queries the database to fill the Cursor object, the return is empty cursor. Not NULL, but empty. On other platforms, I can...

Cursor Error in ArrayAdapter

android,android-arrayadapter,android-cursor
Hello I Need Help displaying palylists name,I Have recently changed from CursorAdapter to Array Adapter due to the error in getting the playlist ID,But now i need to know how to get the Playlist Name;I Use Cursor.GetColumnIndexOrThrow() but it's Returning an Error i dont know anything about: PlaylistFragment: public class...

SQLite updating a row and updating listview created by cursor

android,sqlite,android-cursor
I have a from that a user fills in and their data is stored in a row using SQLite, a cursor gets their details from the table and outputs it in a listView. I want the user to be able to fill in that form again so as to update...

What's practical purpose of cursorLoader?

android,android-sqlite,android-cursor,android-cursorloader
I saw some articles about cursorLoader like this, but i still don't understand the particular purpose of using it. I developed apps with sql and cursor retrieving. The point is it was very fast. I queried and parsed cursor with >500 record and 8 columns by a few millisecond. So...

Android Contacts Content Provider sometimes returns empty phone numbers

android,android-contentprovider,android-contacts,android-cursor
Here is the code used to get the contact information : String id = data.getData().getLastPathSegment(); Cursor cursor = getActivity().getContentResolver() .query(ContactsContract.Data.CONTENT_URI, new String[] {ContactsContract.Data.DISPLAY_NAME}, ContactsContract.Data.CONTACT_ID + "=?", new String[]{id}, null); // short circuit if we didn't pick a contact if (cursor.getCount() == 0) { return; } String contact = ""; String...

How to implement an endless CursorAdapter?

android,android-listview,cursor,android-cursoradapter,android-cursor
At our company we are developing an app that displays a timeline. We are willing to let the user scroll it (almost) indefinitely. Now there are 2 facts to consider: loading a large cursor can have a bad impact on performances (true especially for old devices) cursors seem to have...

How to know what is behind SQLiteCursor's address seen during debugging?

android,android-sqlite,android-cursor
I am debugging an application and when the Cursor retrieves a pointer from the database, I see something like this How can I know what means the value behind @? How can I bind this address to the database value behind it? Why do I need this? The app is...

How to cast the cursor from a fragment to a new activity?

android,android-fragments,android-fragmentactivity,android-cursoradapter,android-cursor
I have a working ListView, in a fragment and when the ListItem is clicked I want to link the data to a new Activity. I am getting an error that my db object cannot be cast to the db Cursor import android.app.ActionBar; import android.app.FragmentTransaction; import android.content.Intent; import android.database.Cursor; import android.os.Bundle;...

DatabaseUtils cursorRowToContentValues converts blob to string

android,cursor,blob,android-cursor
I just stumbled upon a problem with Android's DatabaseUtils.cursorRowToContentValues method. In the cursor the blob is correctly stored as a byte array. cursor.getBlob() also returns the correct value. However after using the utils method to convert it, the ContentValues contain a string and calling getAsByteArray returns null, because there is...

How to retrieve a specific row using SQLite and Cursors?

android,android-sqlite,android-cursor
I want to retrieve a specific user from a SQLite database on Android with a provided username using a Cursor. I've tried this: String[] fields = new String[] { "username", "email", "dateRegister" }; Cursor c = db.query(tableName, fields, "username ='1234'", null); But it isn't working. How can I retrieve a...

StartActivityForResult for multiple buttons accessing one activity and getting different datas on selection?

java,android,android-cursor,start-activity
I'm developing an app in which one of its features is to allow the user to input a phone number or select one from the phones contacts. The activity has 3 EditTexts along with 3 Buttons each on the side, and the buttons open the Contacts Activity and return the...