Android :: Janky Custom Cursor Adapter

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_P­ACKAGE)));

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:........................

Android :: Janky Custom Cursor Adapter


Android :: Trying To Write Custom Adapter For Database Cursor

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

Android :: Add Childs To My Custom View Group With A Cursor Adapter?

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

Android :: Moving Cursor Adapter Cursor Creation To Background Thread

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

Android :: An IF Statement In A Cursor Adapter?

Jul 15, 2010

CODE:...........................

View 1 Replies View Related

Android :: Cursor Adapter With Multi Select

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

Android :: How To Use Simple Cursor Adapter To Include Button?

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

Android :: Is It Worth Writing A ContentProvider - Using Cursor Adapter?

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

Android :: Causes A Redundant Cursor Adapter To View Copy

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

Android :: List View Separators Using A Cursor Adapter

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

Android :: How To Only Show Specific Elements In A Cursor Adapter

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

Android :: Simple Cursor Adapter - List View

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

Android : Binded Spinner Widget - Cursor Adapter?

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

Android :: Photo URI Of Contact Image - Using With Simple Cursor Adapter

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

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 View Related

Android :: Cursor Adapter - Binding Multiple Item Values In ListView

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

Android :: Proper Implementation Of Changing ListView Data With Cursor Adapter

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

Android :: Droid Save Checkbox State In ListView With Cursor Adapter

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

Android :: Implementing Filterable Cursor Adapter - How To Invoke/refresh Filter

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

Android :: Contents Of List View - Using A Cursor Adapter - Are Not Updated Refreshed

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

Android :: Simple Cursor Adapter - List View - Binded To XML Document With Three Text Views

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

Android :: ListView Using Custom ArrayList Adapter - Implementing Custom Filter

Jun 18, 2010

I have seen examples implementing a custom Filter. The Android developer docs talk about implementing a Filterable interface. Does anyone have any advice and/or sample code on the best way to implement filtering in a ListView ?

View 2 Replies View Related

Android :: Custom Adapter - How To Set Row Height?

Jan 31, 2010

How do I set row height if text of some rows more than one line when writing custom ArrayAdapter?

View 4 Replies View Related

Android :: Custom Adapter With Bar Progress

Feb 25, 2010

I have a custom adapter for an arraylist.

CODE:...........

But when i try to access to the progress bar in the adapter

CODE:............

It always return null, like it doesn't find the progress bar. However, the progress bar is shown in the list, but i need to access to it inside the adapter.

View 1 Replies View Related

Android :: Linkify - Using In Custom Adapter?

Jun 7, 2010

I seem to be having trouble with the linkify I am using in my Custom Adapter. For some reason I recieve the following stack track when I click on one of the links:

CODE:......

Here is the code that is calling it:

CODE:.......

I understand what the error is saying but I am not sure how to fix it.

View 1 Replies View Related

Android :: ListAdapter - Cursor - Custom Layout?

Oct 12, 2010

I'm experimenting with the Android platform, and I'm beginning to love it, but right now I'm stuck, at this cursor/list adapter problem-thing.

The thing is, that I request a function, returning a data object, with several properties I'd like to map to different TextView's.

My list_item.xml

CODE:...........

So what I would like to do is: Map a property of an array of objects to several fields in the file.

View 1 Replies View Related

Android :: Custom View Using Adapter Iface

Jan 31, 2009

I want to create custom View showing possibly several items. i think using Adapter interface would be good idea.

My question is: should i extend AdapterView? if so, what is the most imortant when doing this (e.g. AdapterView is ViewGroup, so how should i manage children)?

View 6 Replies View Related

Android :: Cannot Understand NullPointerException With Custom Adapter

Apr 28, 2010

I am trying to create a list view which as TextView that can display html content , an WebView and other basic TextViews.I tried to extend SimpleAdapter but i struck with the problem ,I will be glad if someone can point out the mistake i am doing.

In onCreate method:

CODE:.............

And my row.xml file looks like:

CODE:.............

The error i was getting was:

CODE:..................................

View 1 Replies View Related

Android :: Finalizing Cursor Error In Custom CursorAdapter

Sep 7, 2010

I have a cursor adapter and the logcat is filled with above errors, as soon as I click on a view. I am already releasing the CursorAdapter's cursor in onDestroy().Is there any way to get information about when the cursor was opened?

View 3 Replies View Related

Android :: Checkbox In Listview With Custom Cursor Binding

Feb 14, 2010

I think I've tried everything(made focusable:false!!) and I cant capture in anyway the selected checkbox on my list item. Even OnItemClickListener, doesn't respond to any click. How can I retrieve checked checkboxes in my list item? My list item included: image view, 4 textviews and the checkbox. Some code:

this is in my ListActivity class:
final String columns[] = new String[] { MyUsers.User._ID, MyUsers.User.MSG, MyUsers.User.LOCATION }; int[] to = new int[] { R.id.toptext, R.id.bottomtext,R.id.ChkBox, R.id.Location}; Uri myUri = Uri.parse("content://com.idan.datastorageprovider/users"); Cursor cursor = getContentResolver().query(myUri, columns, null, null, null); startManagingCursor(cursor); ListCursorAdapter myCursorAdapter=new ListCursorAdapter(this, R.layout.listitem, cursor, columns, to); this.setListAdapter(myCursorAdapter);

And this is my Custom Cursor adapter class:
public class ListCursorAdapter extends SimpleCursorAdapter { private Context context; private int layout; public ListCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) { super(context, layout, c, from, to); this.context = context; this.layout = layout;
} @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { Cursor c = getCursor(); final LayoutInflater inflater = LayoutInflater.from(context); View v = inflater.inflate(layout, parent, false); return v;
} @Override public void bindView(View v, Context context, Cursor c) { TextView topText = (TextView) v.findViewById(R.id.toptext); if (topText != null) { topText.setText("");
} int nameCol = c.getColumnIndex(MyUsers.User.MSG); String name = c.getString(nameCol); TextView buttomTxt = (TextView) v.findViewById(R.id.bottomtext); if (buttomTxt != null) { buttomTxt.setText("Message: "+name); } nameCol = c.getColumnIndex(MyUsers.User.LOCATION);
name = c.getString(nameCol); TextView location = (TextView) v.findViewById(R.id.Location);
if (locationLinkTxt != null) { locationLinkTxt.setText(name);
}
I've tried many ways. many listeners, can't figure how to capture listener to my checkboxes. The data I am binding to the list items from the database, isn't concerned about the checkbox.. only the textviews. There isn't any connection between the database and the checkbox I have in the list's item.

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="100sp" android:focusable="false" android:focusableInTouchMode="false"> android:padding="6dip">
<ImageView android:layout_width="wrap_content"
android:layout_height="fill_parent" android:src="@drawable/icon"
android:id="@drawable/icon" android:layout_marginLeft="6dip"
android:focusable="false" android:focusableInTouchMode="false">

</ImageView> <LinearLayout android:id="@+id/LinearLayout01"
android:orientation="vertical" android:layout_width="1sp"
android:layout_height="fill_parent" android:layout_weight="1"
android:focusable="false" android:focusableInTouchMode="false">
<TextView android:id="@+id/toptext" android:layout_weight="1"
android:gravity="center_vertical" android:text="OrderNum"
android:singleLine="true" android:layout_height="0dp"
android:layout_width="wrap_content" android:focusable="false"
android:focusableInTouchMode="false">

</TextView> <TextView android:id="@+id/bottomtext" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:focusable="false"
android:focusableInTouchMode="false" android:text="TweetMsg">
</TextView> <TextView android:id="@+id/twittLocation"
android:layout_weight="1" android:text="location" android:singleLine="true"
android:layout_width="fill_parent" android:layout_height="0dip"
android:focusable="false" android:focusableInTouchMode="false">
</TextView> <TextView android:layout_weight="1" android:id="@+id/twittLocationlink"
android:text="locationlink" android:gravity="fill_horizontal"
android:layout_width="fill_parent" android:layout_height="0dip"
android:focusable="false" android:focusableInTouchMode="false">
</TextView> </LinearLayout>
<CheckBox android:id="@+id/deleteTwittChkBox" android:text="Delete"
android:layout_width="wrap_content" android:layout_marginRight="2dp"
android:focusable="false" android:checked="false"
android:focusableInTouchMode="false" android:layout_height="fill_parent"></CheckBox>

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved