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!

Android :: Implementing Filterable Cursor Adapter - How to invoke/refresh filter


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 :: 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 :: Store Second Value Beside Each String Without Implementing New Adapter Class?

Oct 14, 2010

I want to create a ArrayAdapter for one spinner. So each element contain one string (which will be displayed in the spinner/list) and one value (e.g. an ID). How I can easily store a second value beside each string without implementing a new Adapter class?

View 2 Replies View Related

Android :: How To Refresh Adapter?

Sep 12, 2009

I am developing file browser to my media player UI i have written in my OnItemClickListener() in that i called the method like adapter.notifyDataSetInvalidated() method but it is not working please help me to refresh my list.based on onItemClickListener() method.

View 2 Replies View Related

Android :: Filter Rows From Cursor - Don't Show Up In ListView

Jun 12, 2010

I have a Cursor that returns rows I use with a SimpleCursorAdapter to populate a ListView. I would like to filter some of the rows so they don't get displayed in my ListView. I use the data from the rows elsewhere in my Activity so I don't want to change my SQL to filter them with a WHERE clause. What is the best way to keep a row from being displaying in my ListView? Ideally I would check a column in my row and then only add rows to the ListView that satisfy a condition.

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

View 4 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 :: 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 :: 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 :: How To Refresh Updated Contacts In List View Using Base Adapter?

Jul 23, 2009

Currently I am working on IM, and I am facing problem during implementations. I am implementing this messenger using XMPP client and using smack API for implementing all features like contacts list, online offline status, and chat also. Prblem which I am facing:

Its my list view where I am showing contacts list
public class ContactsList extends ListActivity implements OnClickListener{
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ContactsManager manager = new ContactsManager(this); setListAdapter(manager);
} public class ContactsManager extends BaseAdapter{
private LayoutInflater mInflater; private Bitmap mainListIcons[];
private static ContactsInfo contactsInfo; public ContactsManager(Context context) {
mInflater = LayoutInflater.from(context); mainListIcons= new Bitmap[3];
mainListIcons[0] = BitmapFactory.decodeResource (context.getResources(), R.drawable.online);
mainListIcons[1] = BitmapFactory.decodeResource (context.getResources(), R.drawable.offline);
} @Override public int getCount() { return Global.contacts.size();//
contacts is vector where I am saving my contacts
} public Object getItem(int position) { return position;
} public long getItemId(int position) { return position;
} public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder; if (convertView == null) {
convertView = mInflater.inflate (R.layout.main_settings_lists_icon_text, null);
holder = new ViewHolder(); holder.mainListDisplayText = (TextView) convertView.findViewById(R.id.main_settings_lists_text);
holder.mainListDisplayIcon = (ImageView) convertView.findViewById(R.id.main_settings_lists_icon);
convertView.setTag(holder);}else{ holder = (ViewHolder) convertView.getTag();
} contactsInfo = (ContactsInfo)Global.contacts.elementAt (position);
String username = contactsInfo.getUsername(); String status = contactsInfo.getUserstatus();
if(status.equalsIgnoreCase("unavailable")) { older.mainListDisplayIcon.setImageBitmap(mainListIcons[1]);
}else{ holder.mainListDisplayIcon.setImageBitmap(mainListIcons[0]);
} holder.mainListDisplayText.setText(username); return convertView;
} static class ViewHolder { TextView mainListDisplayText;
ImageView mainListDisplayIcon;}
public class ContactsHandler implements RosterListener {
@Override public void entriesAdded(Collection<String> c) {
for(String s:c) { Log.i("ADDED Contacts",s);
} } @Override public void presenceChanged(Presence p) {
Log.i("PRESENCE",p.getFrom()); Log.i("IS Available",""+p.isAvailable());
Log.i("UserStatus",""+p.getStatus()); if(p.getFrom().contains("@") && p.isAvailable())
{ ChatManager chatmanager = Connection.getVopConnection getXMPPConnection().getChatManager();
Chat newChat = chatmanager.createChat("gulfam@imran-mehmood", new ChatHandler());
} } }

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 :: 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 :: Implementing Sync Adapter / Sync Icon Wont Disappear

Oct 18, 2010

I'm implementing my own sync adapter and everything works great. A strange i'm having is that after the sync is over, the Android still shows the sync icon (the one with the rounded arrow) in the account activity, and that someone (i guess its the account manager) repeatedly calls the sync again and again, every 30 to 60 seconds. Now i tried all sort of things to test this issue and i have discovered something strange. In my code, i do resolver.applyBatch every 50 new rows. (each new contact i sync has about 5 rows). If i remove the applyBatch (which means i retrieve the data from the next, sort it and prepare it, but never "commit" it) - the problem goes away. The icon disappear and the account manager never calls it again on its own (I'm using Android 2.1). I must also state that no exception is being thrown in any of the cases and that all the methods finish gracefully.

View 2 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 :: 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 :: Bug While Selecting From A List Of Multi-select Items Whilst Using Filterable

Feb 23, 2009

I'm displaying the contacts in a Multi-select "Ok, Cancel" dialog box. I've implemented Filterable for the adapter that displays the contacts in the dialog. The problem is, once i try and select(check) a contact while i'm using a type ahead, the check box in that particular position is checked and not the contact.

The initial screen goes like

After type-ahead,

When I hit backspace, the screen appears as,

This is my activity.

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

The adapter goes like,

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

View 4 Replies View Related

Android :: Way To Refresh An Activity / Map View Refresh Fails?

May 3, 2010

After implementing some Android Apps, including several Map activities, I try to refresh the activity when the GPS listener's onLocationChanged() mehtod is called. I have no idea how to tell the map activity to refresh on its own and display the new coords. the coords to store will have to be in global values, so that the location listener will have access to it. In my sample GPS-class (see code below) I just changed the text of a text view....but how to do that in map view?

View 2 Replies View Related

Android :: Join ContentResolver Cursor With A Database Cursor

Mar 21, 2010

I get records from the system by quering a ContentResolver. I maintain the order of the items in the database. So I want to display the items in the order taken from my database.

How do I merge these two informations?

I am looking after an alternative way now. As what I ideally want is:

Get order of contacts by a custom order held in my database (this involves joining CR with my DB cursor, and doing an order by, later seams it's not possible with CursorJoiner) but there is more, if the join is not unique I want to sort by contact's name as last measure

Which is impossible using Cursor and Joiners, because of the missing feature of order bys, also I need to return a Cursor, as I will be using the in an ExpandableList

Also this translated to TSQL it would look like

select * from contactsdata
left join category on contactsdata.catid=category.id
order by category.pos asc, contact.display_name asc

So I am looking now after an alternative. I have in mind to load in a temporary DB table all data from CR, then do the query on the temporary table where I can join tables and do order bys? How does this sound to you?

View 1 Replies View Related







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