android-cursor

Putting cursor data into an array

痞子三分冷 提交于 2019-12-20 10:55:38
问题 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

Android RecyclerView + CursorLoader + ContentProvider + “Load More”

冷暖自知 提交于 2019-12-20 08:02:44
问题 I have created one Activity in that I am implementing CursorLoader for load data from Database. I have done that thing for all records of that Table but I want to load 30-30 records like Load More Functionality I have tried to create query and its loading first 30 records but I cant able to understand how can I request for new records. My Activity Code is Like: public class ProductListActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor> { /** * Records in list *

Android development with sqlite: query result shouldn't be empty

℡╲_俬逩灬. 提交于 2019-12-20 06:38:15
问题 I have a rather big query that is returning data when executed outside android while returning nothing when executed within android. I split the query in several pieces and determined that the union was ok. I tried on a smaller set of data with the same behavior. I've tested with different hardware and API versions. I'm using the rawQuery method with constant values. http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#rawQuery(java.lang.String, java.lang.String[

IllegalStateException: attempt to re-open an already-closed object. SimpleCursorAdapter problems

孤者浪人 提交于 2019-12-20 02:49:11
问题 I'm totally new to android programming. I can see that this problem has been raised many times before. However, I am still not able to see what the problem is. I'm trying to connect the data from an SQLite database to a listview. In the ListActivity my onCreate looks like the following: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_init_key); getActionBar().setDisplayHomeAsUpEnabled(true); DBHandler db = new DBHandler

Getting a column from .sqlite containing multiple tables with multiple columns

妖精的绣舞 提交于 2019-12-18 09:55:40
问题 !Database consists of multiple tables and multiple columns as shown & i have pasted this law.sqlite in assets folder. Database consists of multiple tables and multiple columns as shown & i have pasted this law.sqlite in assets folder. Suppose i want to access all the elements of column AS_name as shown . So how should i code for it? 回答1: Try this: Cursor cursor = db.rawQuery("SELECT DISTINCT AS_name FROM Articles",null); // If you want in order then add "ORDER BY AS_name AESC" in sql query.

Passing binary blob through a content provider

对着背影说爱祢 提交于 2019-12-18 04:13:10
问题 I have a content provider that is custom to my set of Android applications, and one of the things it needs to expose is a small (20-30 KiB) byte array. The URI for these blobs looks like: content://my.authority/blob/# where # is the row number; the resulting cursor has the standard _id column and a data column. I'm using a MatrixCursor in the provider's query() method: byte[] byteData = getMyByteData(); MatrixCursor mc = new MatrixCursor(COLUMNS); mc.addRow(new Object[] { id, byteData });

Inverted ListView in Android?

折月煮酒 提交于 2019-12-17 20:07:07
问题 Is there an easy way to display a ListView in reverse order? I am trying to create a conversation-based app, and would like the most recent entries to be at the bottom of the ListView. I am aware of transcriptMode and stackFromBottom, however my problem is the order of the data. Say I have 100 conversation items, and want to display items 80-100, with 100 being the most recent conversation item. I would like to show 80-100, which implies an ORDER BY id desc LIMIT 20 in my query, which forces

How to disable cursor positioning and text selection in an EditText? (Android)

馋奶兔 提交于 2019-12-17 18:28:43
问题 I'm searching for a way to prevent the user from moving the cursor position anywhere. The cursor should always stay at the end of the current EditText value. In addition to that the user should not be able to select anything in the EditText. Do you have any idea how to realize that in Android using an EditText? To clarify: the user should be able to insert text, but only at the end. 回答1: I had the same problem. This ended up working for me: public class CustomEditText extends EditText {

How can I create a list Array with the cursor data in Android

假装没事ソ 提交于 2019-12-17 15:27:29
问题 How can I create a list Array (the list display First Alphabet when scroll) with the cursor data? 回答1: Go through every element in the Cursor , and add them one by one to the ArrayList . ArrayList<WhateverTypeYouWant> mArrayList = new ArrayList<WhateverTypeYouWant>(); for(mCursor.moveToFirst(); !mCursor.isAfterLast(); mCursor.moveToNext()) { // The Cursor is now set to the right position mArrayList.add(mCursor.getWhateverTypeYouWant(WHATEVER_COLUMN_INDEX_YOU_WANT)); } (replace

Sorted list of contacts having duplicates ,why?

我怕爱的太早我们不能终老 提交于 2019-12-17 14:51:48
问题 I have sorted and listed my phone contacts in to an arraylist but ,i got many duplicates of same contact names in the list .How this happens? how to avoid this? This is what i have tried, cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, "(" + ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + ") ASC"); while (cursor.moveToNext()) { try { name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME