Android :: Cursor Adapter Making My Display Choppy - When I Scroll
Jul 26, 2010
can anyone tell me what im doing wrong with my cursorAdapter? its making my display choppy when i scroll. I used to have it within a getview but was ripped (rightfully so) on IRC several times because thats not the right place for it. Im still learning and just trying to correctly wrap my head around things.
http://pastebin.com/Dc5ppHUM
View 3 Replies
Mar 29, 2010
The structure of some of my activities is a simple ListView with a custom CursorAdapter. The cursor is created in onCreate() on the activity from a SQLite database. The problem is that querying the SQLite database can be quite slow at times with lots of data (and let's assume I've already optimized the sql query as much as possible). Because it occurs in onCreate() on the UI thread, I get ugly black screens when opening the activity, which sometimes turn into ANRs, on a slow phone like the G1. I want to load the cursor in a background and show "Loading.." on screen while doing so. I saw AsyncQueryHandler used extensively in the framework, but this seems a solution geared more towards Content Providers and not application-local SQLite databases. I then thought of trying to load the cursor in a background thread, but realize that this might be problematic, as the CursorAdapter should be instantiated in onCreate() and should take a cursor as a parameter. The latest thought I had was to instantiate an empty MatrixCursor in onCreate() and pass that to the cursor adapter, while kicking off a thread/TimerTask to query the database. Then, on database cursor load, call cursorAdapter.change Cursor to the properly filled cursor. This doesn't seem very elegant and seems quite wasteful, however.
View 10 Replies
View Related
Apr 19, 2010
I have text area and and down to that "ok" and "cancel" button. when i click on text area keyboard appear and focus on the text area and buttons get hide behind the keyboard.
I want when text area get focus scroll a little bit and also display the bottom buttons while text area id selected.
View 2 Replies
View Related
Jul 15, 2010
CODE:...........................
View 1 Replies
View Related
Nov 11, 2010
I've written an APP the uses has a small SQL lite DB and using a cursor adapter I can retrieve the records and populate a list view with them. from there I can get the Id of a selected item and delete it from the DB which works great. the issue I have is that as the DB grows deleting one row at a time would be slow and frustrating so I wanted to know if there was any way to allow multiple selections possibly with check boxes or by even changing the text color of the items selected so that I can retreiving their relative ID's.
I have read some posts that talk about custom cursor adapters but I am not sure how to adapt them to my code.
I have posted my code below.
CODE:.........................
View 1 Replies
View Related
May 25, 2010
I have a Custom Cursor Adapter. It shows a list of installed applications with an icon, name and checkbox on each line item. I cache the list of applications in a database for faster retrieve and to store the state of the checkbox. However, I can't store the application icon in the db because sqlite doesn't support blobs. They list works rather well except that it is "janky" as described by Brad Fitzpatrick at Google IO (https://wave.google.com/wave/waveref/ googlewave.com/w+3kgmObZwO ). I'm trying to make my app non-janky by following the tutorial here: [url]... but I'm having trouble.
The reason my list is janky is because I look up each icon as you scroll down the list. drawable = pm.getApplicationIcon(c.getString(c.getColumnIndex(SmartLockDbAdapter.KEY_PACKAGE)));
getApplicationIcon takes too long to return to make for a smooth scrolling list. I would like to perform the action in the background with an AsyncTask but because bindView gets called repeatedly in a short time span, my icons end up with the wrong list item. I need help.
I've posted my whole ListActivity below in hopes that it helps other people. It's much harder to find an example of a working CursorAdapter then it is an ArrayAdapter.
CODE:........................
View 4 Replies
View Related
Jun 9, 2009
I have read the Gallery2.java example, which show how to map a Column's value to an element in the view I want to create (in this case, it maps 'NAME' to text1 element0. But what if I have a Button in my view, how can I know which Person is being clicked? or how can I query the person's info when a button in the new is clicked?
From the Gallery2.java example:
SpinnerAdapter adapter = new SimpleCursorAdapter(this,
// Use a template that displays a text view
android.R.layout.simple_gallery_item,
// Give the cursor to the list adatper c,
// Map the NAME column in the people database to...
new String[] {People.NAME},
// The "text1" view defined in the XML template
new int[] { android.R.id.text1 });
Gallery g = (Gallery) findViewById(R.id.gallery);
View 2 Replies
View Related
Sep 14, 2010
We are connecting to a number of WebServices and fetching a lot of structured data(XML). We are parsing this data and storing them into SQLite tables. This part of the application runs periodically in the back ground.
On the foreground, the data fetched is displayed in ListViews. We have used ArrayAdapter to back these lists up. The thing is, every time the Actvity starts or data set is refreshed, we have to load the ArrayLists by querying the database and call notifyDataSetChanged() on the Adapter. This slows down the application and affects the User experience.
Question: 1. I'd imagine using a CursorAdapter might result in performance gain, since the framework will take care of managing the cursor. Is this assumption valid? 2. Will the CursorAdapter take care of reflecting updates to the database on the screen automatically? 3. Will I have to write a ContentProvider if I choose to use CursorAdapters? 4. Are there any other considerations that we need to make?
View 6 Replies
View Related
Jun 29, 2009
I been using custom adapters based on the BaseAdapter and I usually populate my data at the getView() funtion.
Now I'm trying to write my custom adapter for my database cursor which now will be based on a CursorAdapter.
I'm getting confused where I should do the populating work? Along with how do I implement my inflating and populating "smart/efficient code based on RomainGuy presentation."
View 8 Replies
View Related
Oct 28, 2009
CursorAdapter is great, i'm a big fan. I notice that both newView() and bindView() are passed Cursors, indicating that extracting stuff from the Cursor and sticking it in the view should happen inside those overrides.
however in the source for CursorAdapter.getView() i see that bindView() gets called whether the view is recycled or not. in the new view case, this causes a redundant Cursor to View copy.
IMHO, CursorAdapter should call newView() if the view couldn't be recycled, or bindView() if it could.
View 3 Replies
View Related
Oct 5, 2010
I have a ListView which is populated using a CursorAdapter. I'd also like to have some separators in my ListView. I have accomplished this with an ArrayAdapter, but I'm not sure how to accomplish this with a CursorAdapter. Are there any strategies for doing so? Or am I out of luck?
View 1 Replies
View Related
Jul 23, 2010
I have a custom CursorAdapter that is taking items from a database and displaying them in a listview. If possible, I would like to display only certain elements based on some boolean value within a database element. Here is something similar to what I would like to do:
package itp.uts.program;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;
//Adapter tests if an element is read or unread, and bolds the items that are unread
public class BoldAdapter extends CursorAdapter. Code...
View 2 Replies
View Related
Jun 9, 2010
I have table with 3 columns which is binded to an XML document with three text views.
CODE:........
Depending on the value store in the third column, I have to decide whether i should display this row or not
How should, I go about with this.
This is what I have so far :
CODE:...............
View 2 Replies
View Related
Aug 24, 2009
I successfully binded a spinner widget to a simple cursor adapter, but I started having problems when I tried to add a new item to the table which feeds the spinner by clicking an "add new item" button. The idea was to launch a new activity which returns the rowid of the just added element, and use it to set the new position.
What I basically did is to implement something like:
break; in the "onActivityResult" method, the rowid has the correct value but setSelection has no effect. I also tried to force the argument to some other values, but still with no result. If I call it in the onCreate method, it works beautifully. Moreover, I am still not sure that setSelection is the right method to call, since its arg is named "position" in the doc, while I am passing an "id".
View 2 Replies
View Related
Apr 8, 2010
I want to write a short app for getting some info from contacts, the first list screen I have should display the user Image (or an Image from resources if no such image exists) an the user display name. The problem is I don't seem to find a query that will provide me with the display name and a user id And the image URI in the same query. Moreover I'm aware of the fact that if the user has no image and the URI is empty or null i will most likely to get an exception while the adapter calls setViewImage(). Is there a simple way around it or should I override the setViewImage() or bindView() methods?
Also about the query, any chance I can make a single query for contact URI, _ID, contact_id and display name? my current queries: To get the contacts:
private Cursor getContacts() { Uri uri = ContactsContract.Data.CONTENT_URI;
String[] projection = new String[] ContactsContract.Data._ID,ContactsContract.Data.CONTACT_ID,
ContactsContract.Data.DISPLAY_NAME };
String selection = ContactsContract.Data.MIMETYPE + " = ?";
String[] selectionArgs = {ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE};
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " ASC";
return managedQuery(uri, projection, selection, selectionArgs, sortOrder); }
If I have a contact id and want the image:
int _id = m_cursor.getColumnIndex(ContactsContract.Contacts._ID);
//try to retrieve the photo, if exists.
Uri photoUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI,
m_cursor.getLong(_id)); InputStream is = ContactsContract.Contacts.openContactPhotoInputStream(m_context.getContentResolver(), photoUri);
Here I get from a cursor with _ID column the id and then creating the uri, I know I can get a row number but I'm not familiar enough with contentProvider to know how to join tables to get it all in one query (if even possible).
View 2 Replies
View Related
Oct 13, 2010
I've got a schedule Class, which is simply a custom ViewGroup (with custom onMeasure() and onLayout()), which enables me to place childs(=events) with LayoutParams for column/row start and column/row end. The number of childs and their LayoutParams depend on database entries.
Now I'm trying to add childs (events) from my database. I'd have to use a Cursor Adapter, so my schedule Class has to extend ListView, right? I tried that but the newView() method of the adapter is never called. Why not? My custom ListView doesn't ask the adapter for childs, no childs are added. I also can't add the childs by hand calling schedule.addView() if I extend from AdapterView.
How can I add events to the schedule with the data from the cursor?
View 1 Replies
View Related
Jan 12, 2010
I have the following code to intantiate a SimpleCursorAdapter to use with a ListView. As you can see I have passed the R.layout.log_item to display the list items, and one value/control to bind to (TripDate).
SimpleCursorAdapter sca = new SimpleCursorAdapter(this, R.layout.log_item,c,new String[] {DBAdapter.KEY_LOG_TRIPDATE},new int[]{R.id.txtTripDate});
This works. I currently only have one widget in the layout xml, a TextView to hold the TripDate.
How do I pass multiple binding parameters for the additional widgets in the layout? So I can also display other info.
View 1 Replies
View Related
Sep 3, 2010
I have a ListView populated via a CursorAdapter. I give my user the ability to alter the data in the list. For example, the user can mark a row as being unread (the data are messages).
Suppose my user marked a row unread. Would a proper implementation mark the row in the database as read and then requery the Cursor?
View 1 Replies
View Related
Mar 9, 2010
I cant find a way to save the checkbox state when using a Cursor adapter. Everything else works fine but if i click on a checkbox it is repeated when it is recycled. Ive seen examples using array adapters but because of my lack of experience im finding it hard to translate it into using a cursor adapter. Could someone give me an example of how to go about it.code...
View 3 Replies
View Related
Jun 15, 2010
I've overriden runQueryOnBackgroundThread and done what I've needed to do for the corrent query to be excuted with a given constraint. My current challenge is figuring out how to actually pass in the constraint. I've got an ActivityList which I'd like to filter on a stored preference. I'm thinking I will need to perform a filter during onStart such that the most recent preference changes are picked up. All that is in place, just not clicking on how I'd actually cause the filter to happen!
View 2 Replies
View Related
Aug 26, 2010
I have a list which shows data from a database using a cursor adapter. Using Menu option I am updating my database (inserting more rows deleting existing rows). When Menu operation completes, I want contents of list should show updated contents.
I have tried using cursor.requery(); (or explicitly querying cursor again) and using adapter.notifydatasetchanged(), but with this list of contents are not updated.
How can I refresh the contents of the list.
View 2 Replies
View Related
Aug 4, 2010
I have a listview with a custom arrayadapter that handles about 15 strings. The style of each row alternates (between labels and values for those labels--for example row 1 could be "email address" and row 2 would be the actual email address). I'm changing the style of each row to alternate like this in the arrayadapter's getView() method. So if the item at the current position is a label, I'll change the styling from the default row style (which is what the values have applied to them). When the listview first loads, the styling is perfect and just how I want it to be. If I scroll the list slowly up or down, it stays that way. However, if I scroll the list fast up and down, the styling of the value rows starts changing to that of the label ones until all of the rows have the styling of a label row. I've used custom adapters on other listviews in the app with no problems like this. Found out that it also changes all of the rows to the label styling on portrait->landscape orientation changes. Doesn't do this on landscape->portrait changes. Below is the adapter I'm using.
public class DetailsAdapter extends ArrayAdapter<String> { private TextView text = null; private String item = null;
public DetailsAdapter(Context context, int resource, int textViewResourceId, String[] objects) { super(context, resource, textViewResourceId, objects);
} @Override public View getView(int position, View convertView, ViewGroup parent) { text = (TextView) super.getView(position, convertView, parent); item = getItem(position);
if (item.equals("Name") || item.equals("Mobile") || item.equals("Home") || item.equals("Email") || item.equals("Address")) { text.setBackgroundColor(0xFF575757); text.setTextSize(15);
text.setTypeface(null, Typeface.BOLD); text.setPadding(8, 5, 0, 5);
} else { text.setPadding(15, 15, 0, 15); } return text;
} @Override public boolean isEnabled(int position) { item = getItem(position);
if (item.equals("Name") || item.equals("Mobile") || item.equals("Home") || item.equals("Email") || item.equals("Address")) { return false;
} else { return true; } } }
View 1 Replies
View Related
Mar 18, 2009
I have table with 3 columns which is binded to an XML document with three text views.
CODE:........
Depending on the value store in the third column, I want to change the text color in R.id.c. How should, I go about with this.
This is what I have so far :
COD:...............
View 3 Replies
View Related
Oct 2, 2009
How to load data in expandable List Adapter through Scroll .
Means I want to add data as per Scrolling in Run time.
View 1 Replies
View Related
Jan 29, 2010
I am trying to make a terminal type app that is wider than the actual android screen. A listview is great except that I don't want the text to wrap. If the text is wider than the screen I want it to print the full text and then the user can scroll over horizontally if they want to see what was printed off the screen. Just FYI this is for ascii type tables. I have followed this example:
It works great as far as horizontal text goes it does exactly what I want but I am unable to get the ListView inside the custom LinearLayout to actually scroll veritcally. I have tried passing the Y coordinates from the onScroll method to mListView such as: mListView.scrollBy(0, distanceY); but that seems to move the custom LinearLayout window instead of just scrolling the ListView. I can tell that the ListView is not scrolling because the window moves without the vertical scroll bar of the ListView moving.
View 1 Replies
View Related
May 29, 2009
I am new in Android application programming.I need to develop an android application which simply displays the cursor position (co ordinates) very urgently.If any has some pointers in same would be a great help to me.
View 4 Replies
View Related
Oct 12, 2010
When my phone is plugged in my cursor jumps to the left making it impossible to type or access applications that are not on the menu screen all the way to the left. It also navigates itself away from web pages and I think the constant left motion of the cursor makes the phone run slowly. I cant look at maps either.
View 2 Replies
View Related
Jul 12, 2010
I am calling one webservice.Result of webservice I am storing in an Array list. Result of webservice I want to display as list view. For ListView I am using SimpleAdapter. and SimpleAdapter is something like this:- SimpleAdapter adapter = new SimpleAdapter(this,hashmap, layout, from, to);
I am not able to put array list into hashmap. Is there anyway to do this?
View 2 Replies
View Related
Jul 16, 2010
The same code that displays the lists running on the emulator doesn't run on the mobile (Motorola Milestone). I'm using the same android platform (2.1-update).
Inbox Code...
TextView subject_textview = (TextView)rowLayout.findViewById(R.id.subject_textview);
subject_textview.setText(email.getSubject());
String body_hint = " - " + email.getBodyHint();
TextView bodyhint_textview = (TextView)rowLayout.findViewById(R.id.body_hint_textview);
bodyhint_textview.setText(body_hint);
String sender_name = get_sender_name(email.getSender());
TextView sender_name_textview = (TextView)rowLayout.findViewById(R.id.sender_textview);
sender_name_textview.setText(sender_name);
TextView date_time_textview = (TextView)rowLayout.findViewById(R.id.date_time_textview);
date_time_textview.setText(email.getTime());
Stack Trace
07-16 14:00:49.690: WARN/System.err(703): java.lang.ArrayIndexOutOfBoundsException
07-16 14:00:49.698: WARN/System.err(703): at com.anubis.mail.Inbox.populate_list(Inbox.java:237)
07-16 14:00:49.698: WARN/System.err(703): at com.anubis.mail.Inbox.onCreate(Inbox.java:69)
07-16 14:00:49.698: WARN/System.err(703): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-16 14:00:49.698: WARN/System.err(703): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
07-16 14:00:49.706: WARN/System.err(703): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
07-16 14:00:49.706: WARN/System.err(703): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
07-16 14:00:49.706: WARN/System.err(703): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
07-16 14:00:49.706: WARN/System.err(703): at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 14:00:49.706: WARN/System.err(703): at android.os.Looper.loop(Looper.java:123)
07-16 14:00:49.706: WARN/System.err(703): at android.app.ActivityThread.main(ActivityThread.java:4363)
07-16 14:00:49.706: WARN/System.err(703): at java.lang.reflect.Method.invokeNative(Native Method)
07-16 14:00:49.706: WARN/System.err(703): at java.lang.reflect.Method.invoke(Method.java:521)
07-16 14:00:49.706: WARN/System.err(703): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-16 14:00:49.706: WARN/System.err(703): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-16 14:00:49.706: WARN/System.err(703): at dalvik.system.NativeStart.main(Native Method)
View 2 Replies
View Related
Nov 22, 2009
I'm having a little difficulties while trying to get a certain layout to work: I want to have list. List does not have to be scrollable, but should be shown completely. But the page itself should be able to scroll (with the lists in it), if the total content ist higher than the screen.
CODE:.................
It only uses a small part of the screen (about 2 lines per list), instead of filling the available height, and the lists themselves can be scrolled. How can I change the layout to always show the whole lists but have the screen be scrollalbe?
View 3 Replies
View Related