[android-developers] Re: How to update a Cursor

2009-04-24 Thread Mark Murphy

Meryl Silverburgh wrote:
 Hi,
 
 I call ContentResolver's query method to get a Cursor, and I would
 like to update the title of that row to 'new title'
 can you please tell me how to do it?
 
 final ContentResolver cr = context.getContentResolver();
  Cursor c = cr.query(MY_CONTENT_URI,
 new String[] { title}, title=?,
 new String[] { title }, null);
 
 if (c.getCount()  0) {
  // want to update the title to 'new title'
 
 }

context.getContentProvider().update()

There is no update() method on Cursor.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android App Developer Books: http://commonsware.com/books.html

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: How to update a Cursor

2009-04-24 Thread Meryl Silverburgh

Thank you.

I have another question about cursor.

I have inserted a ContentValue like this:
  final ContentResolver cr = context.getContentResolver();

  ContentValue values = new ContentValues();
 values.put(title, new title);
  values.put(x, 10);

  Uri result = cr.insert(CONTENT_URI ,
values);

But why when I do my query and then getColumn, I get
 java.lang.IllegalArgumentException: column 'x' does not exist

   Cursor c = cr.query(CONTENT_URI,
new String[] { title }, title=?,
new String[] { new title }, null);

  if (c.getCount() 0) {
 // get an exception here:
   int xColumn = c.getColumnIndexOrThrow(x);
  }

On Fri, Apr 24, 2009 at 3:03 PM, Mark Murphy mmur...@commonsware.com wrote:

 Meryl Silverburgh wrote:
 Hi,

 I call ContentResolver's query method to get a Cursor, and I would
 like to update the title of that row to 'new title'
 can you please tell me how to do it?

 final ContentResolver cr = context.getContentResolver();
  Cursor c = cr.query(MY_CONTENT_URI,
             new String[] { title}, title=?,
             new String[] { title }, null);

 if (c.getCount()  0) {
  // want to update the title to 'new title'

 }

 context.getContentProvider().update()

 There is no update() method on Cursor.

 --
 Mark Murphy (a Commons Guy)
 http://commonsware.com | http://twitter.com/commonsguy

 Android App Developer Books: http://commonsware.com/books.html

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: How to update a Cursor

2009-04-24 Thread Mark Murphy

Meryl Silverburgh wrote:
 Thank you.
 
 I have another question about cursor.
 
 I have inserted a ContentValue like this:
   final ContentResolver cr = context.getContentResolver();
 
   ContentValue values = new ContentValues();
  values.put(title, new title);
   values.put(x, 10);
 
   Uri result = cr.insert(CONTENT_URI ,
 values);
 
 But why when I do my query and then getColumn, I get
  java.lang.IllegalArgumentException: column 'x' does not exist
 
Cursor c = cr.query(CONTENT_URI,
 new String[] { title }, title=?,
 new String[] { new title }, null);
 
   if (c.getCount() 0) {
  // get an exception here:
int xColumn = c.getColumnIndexOrThrow(x);
   }

Your table or content provider may not have a column named x.

Just because you pass such a value in the ContentValues on insert() does
not mean it will get stored, if there is no pre-defined place to store it.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 2.0 Available!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---