simplecursoradapter

How to add an item to SimpleCursorAdapter?

只谈情不闲聊 提交于 2019-12-06 07:25:21
I have a simple database table with 2 columns "_id" and "title". and I'm displaying the data in a spinner, and it works well. but I need to add one more item at the top of the spinner list that is not from the database with id = 0 and title = "not specified"; Spinner list = (Spinner) findViewById(R.id.spinner); Cursor cursor = database.getAll(); // returns cursor with objects String[] columns = new String[] {"title"}; int[] to = new int[] {R.id.title}; list.setAdapter(new SimpleCursorAdapter(this, R.layout.object_item_simple, cursor, columns, to)); I need to know the selected item id from the

I cannot figure out how to correctly use notifyDataSetChanged within my app

你离开我真会死。 提交于 2019-12-06 05:23:23
I have an app that uses a ViewPager and Fragments to create tabs. Within my app, I have a chat function. Whenever a chat is received or sent, it is stored in a table of the database. The received chats are coming in on a different thread, and the user's chats are being entered into an EditText window in the Chat fragmenet. I have a class called "LogChat.java" that saves the chats to the database. I have a ListView backed by a SimpleCursorAdapter that is displaying the chats. This ListView is in the Chat Fragment of my application. Everything is working perfectly, except the ListView is not

Android - Does SimpleCursorAdapter allow multiple layouts like BaseAdapter?

帅比萌擦擦* 提交于 2019-12-06 05:16:42
问题 I know you can create a custom Adapter extending BaseAdapter and create various layouts which can be inflated depending on which row the AdapterView is at.. But is there any way to get a simple amount of customization with a SimpleCursorAdapter ? Eg. I have a database and I would like to query it and return the results to a ListView with alternating row layouts. Will SimpleCursorAdapter do? Or are there any elegant solutions for this? Cheers 回答1: But is there any way to get a simple amount of

NullPointerException with SimpleCursorAdapter

混江龙づ霸主 提交于 2019-12-06 00:28:12
Trying to set up a gridview with a custom adapter, I get my cursor and set the adapter in ASyncTask... Here is my code for it all: private class getAllData extends AsyncTask<Context, Void, Cursor> { protected void onPreExecute () { dialog = ProgressDialog.show(Shows.this, "", "Loading shows. Please wait...", true); } /** The system calls this to perform work in a worker thread and * delivers it the parameters given to AsyncTask.execute() */ @Override protected Cursor doInBackground(Context... params) { // TODO Auto-generated method stub JSONParser.getAllData(params[0]); c = mDbHelper

CheckedTextView not checked

隐身守侯 提交于 2019-12-05 10:11:54
I want a Multiselected (checked) listview . When I select an item then the green check mark must appear. For this I use CheckedTextViews . The ListView gets the data from the database. I'm using a SimpleCursorAdapter for that. When you click on the button then the selected entries(IDs) will be passed to the next activity. My problem is that the check marks of the CheckedTextView does not appear. But the IDs will be passed to the next activity. What am I doing wrong? How to fix it? selecttest.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com

Why cursorLoader didn't notify changes in source data?

女生的网名这么多〃 提交于 2019-12-05 05:17:40
I have a simple contentProvider, a layout with a ListView and a button for adding Items in content Provider and a CursorLoader. The http://developer.android.com/reference/android/app/LoaderManager.LoaderCallbacks.html#onLoadFinished(android.content.Loader , D) reference states that The Loader will monitor for changes to the data, and report them to you through new calls here. You should not monitor the data yourself. For example, if the data is a Cursor and you place it in a CursorAdapter, use the CursorAdapter(android.content.Context, android.database.Cursor, int) constructor without passing

Android SimpleCursorAdapter results not displaying in AlertDialog

别来无恙 提交于 2019-12-04 21:06:06
I was looking for an alternative to a spinner, since the first item is always selected (which causes me issues), and I found some examples for using an AlertDialog with a list instead. I am having two problems: The list is displaying and is formatted ok, but there are no values in it. I know the query is returning, and the cursor/adapter has the data in it. This may be a symptom of #1 - but when I select a blank row, the Cursor cursor2 = (Cursor) ((AdapterView) dialog).getItemAtPosition(which); statement causes a crash (it's a ClassCastException). I had similar code previously which set the

Using pagination with CursorLoader and MergeCursor closes old cursors

早过忘川 提交于 2019-12-04 18:08:49
As the title says, when trying to paginate a ListView backed by a SimpleCursorAdapter and a CursorLoader , old cursors are getting closed, thus the below exception is being thrown. The first 2 pages load just fine (the first isn't using the MergeCursor and the second page is the first one to use the MergeCursor ). I don't call any close() on any cursor whatsoever. What is interesting is that while debugging, I cannot see the closed flags on any cursor being set as true, for what it's worth. Might be an issue with the MergeCursor then. Let me know if you guys have any solutions, I'm out of

simplecursoradapter not working

徘徊边缘 提交于 2019-12-04 17:17:37
I am using a database, getting a cursor out of it and then using a simplecursoradapter to populate a listview. I can't seem to figure out why the app crashes on creating a new simplecursoradapter. My cursor is contained in a singleton object. I have a reference to it through the data variable in this class. String[] columns = new String[] {"item", "quantity", "days"}; int[] to = new int[] { R.id.nametext, R.id.quantitytext, R.id.dayslefttext}; SimpleCursorAdapter sCA = new SimpleCursorAdapter(this, R.layout.itemrow, data.listCursor, columns, to); listView1.setAdapter(sCA); What does the

ListView empty if SimpleCursorAdapter closed()

丶灬走出姿态 提交于 2019-12-04 11:33:36
I have a problem understanding why is my ListActivity and its corresponding listView empty when I call close() method on cursor object? Let me explain myself a bit... I retreive some values from a DB and get the result in my cursor object. After that I create my SimpleCursorAdapter and bind column from db with a field in my listView . Works like a charm, but... If I call cursor.close() at the end of onCreate() method my listView is shown empty? If I log the values from cursor to LogCat they're there until calling cursor.close() and that makes perfect sense, but why is the listAdapter emptied