Android : Adding A "column" - Data To A Database Cursor

Jan 10, 2010

Maybe I'm going about this the wrong way, but if so, please correct me. Here is the situation: I have a query which returns URI strings for ringtones stored in a database.

I am trying to add a "column" to this cursor with the ringer "Title" (since this can change outside my program). I can successfully user RingtoneManager to get the title, but I cannot figure out how to add this "column" to the cursor data for later use. Here is what I have so far: Code...

Android : Adding a "column" - data to a database cursor


Display BarGraph With Sqlite Database Column Data

May 8, 2013

I am developing an application in android allowing the user to maintain his weight by providing him diet suggestions. I have done with that part and now, I need to display user weight tracking details using bar graph. I am able to fetch the Weight and Login date column data from the sqlite database to List<String>. I don't understand the way to put these values into a Bar Graph with Date Column data as X-axis and Weight column data as Y-axis.

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

Android :: Adding Custom Column To Contacts

Jul 31, 2010

I am trying to add a custom data field to a contact, its UID is known.

I have not yet understood what exactly I should do. I saw and tried other code , but to no success.

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

And "mod" is always 0.

View 3 Replies View Related

Android :: ID Column In Contacts Database

Nov 12, 2010

I read that the different entries in different tables are linked via the _ID column in that table. For example a contact might have an _ID = 1 I get via

ContactsContract.Contacts._ID

And now I want to read the phone number of that contact using

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

This works fine, but what I would expect is that if the _ID of the contact is 1 that the _ID of the phone number is as well one since they belong together, but they are not equal. So the question is how does Android match these entries?

View 1 Replies View Related

Android :: Rename Column Sqlite Database?

Oct 12, 2009

I have a database that I download external and save on my sdcard. But this database is also used for an iPhone app and has a column id and not _id (sqlite uses _id). How can i rename this column to _id?

View 4 Replies View Related

Android : Delete Row In Database Table Given One Column Value - Which Is A String

Jul 22, 2010

I have a table with column headings: | _id (long) | Name (String) | x (integer) | y (integer) |

I want to delete the row in the table that has Name myName.

// In onCreate
dbHelper = new DBAdapter(this);
dbHelper.open()

// Function in DBAdapter class
public boolean deleteTitleGivenName(String myName)
{return dbHelper.delete(DATABASE_TABLE_2, KEY_NAME + "=" + myName, null) > 0;}

// Function call in java code
dbHelper.deleteTitleGivenName(myName); // this is where my code fails

dbHelper.close();

Just as a note: myName is for sure in the database. Also, I can not use the ROWID since I am getting myName from a ListView.

I just started programming with Android and I have tried for days to solve this problem.
Is my WHERE clause correct (KEY_NAME + "=" + myName)?

View 2 Replies View Related

Android :: Get Respective Value From A Database Table Where One Of Column Values Are Displayed In List View

Nov 24, 2010

I have created a table named train_table in SQLite database with 3 columns. they are train_id, train_no and train_name. Now, i wrote a class in which i displayed the train_name in a list view. how do i get the related train_no in the next page? can anyone help me in sorting this problem.?

View 2 Replies View Related

Android :: Adding Headers To Listview For Cursor With Grouped Results

Jul 30, 2010

Requirement: Display query results in a list with a header view atop each group. (results grouped from database) Looking at Mark's MergeAdapter. Wondering if I might be able to use a single cursor and have each adapter filter on the group field? That a viable approach?

View 9 Replies View Related

Android :: How To Use Other External Cursor / Prepare By SQL Database?

Sep 21, 2009

In the API Demo, there is example on using Simple Cursor Adapter. However, it is using the MediaS tore cursor. Is there any method so that I can use other external cursor prepare by SQL database. I don't know what should I input to the from String.

View 2 Replies View Related

Android :: How To Import Cursor From Database Class Into Current One?

Jul 1, 2010

Here is my code for my db class:
package one.two;
import java.util.List;
import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import java.util.ArrayList;
public class DBAdapter extends ListActivity
{public String status = "status";
public String id = "id";
public String arrival = "arrival";
public String destination = "destination";
public String ferry = "ferry";
private static String DB_PATH = "/data/data/one.two/databases/";
private static final String DATABASE_NAME = "ferry.db";
private static final String DATABASE_TABLE = "port";
public static Context context;
public Cursor c;
public static SQLiteDatabase DbLib;
//overloaded non-null constructor
public DBAdapter(Context context) {
DbLib = context.openOrCreateDatabase(DATABASE_NAME,
SQLiteDatabase.CREATE_IF_NECESSARY,null);
System.out.println("OpenOrCreateDB Done");
} public class DatabaseHelper extends SQLiteOpenHelper {
Context context;
DatabaseHelper(Context context){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.context = context;
}//end constructor DatabaseHelper
// ---closes the database---
public void close() {
DBHelper.close();
}//end close()
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion){
}//end onUpgrade()
@Override
public void onCreate(SQLiteDatabase db){
}//end onCreate()
}// end class DatabaseHelper
private static DatabaseHelper DBHelper;
private static final int DATABASE_VERSION = 1;
public static ArrayList<String> getAllTitles(){
ArrayList<String> port = new ArrayList<String>();
Cursor c=null;
c = DbLib.query("port"
new String[] { "status", "id", "arrival",
"destination", "ferry" }, null, null,
null, null, null);
try {
if (c!=null) { // start - when there is at least 1 record
System.out.println("Cursor is NOT NULL");
int i =0;
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext())
{// Debug Stm
System.out.println("Record No. "+i);
System.out.println(c.getString(0));
System.out.println(c.getString(1));
System.out.println(c.getString(2));
System.out.println(c.getString(3));
System.out.println(c.getString(4));
// Assign database cursor.records to arraylist
port.add(i,c.getString(0));
port.add(i,c.getString(1));
port.add(i,c.getString(2));
port.add(i,c.getString(3));
port.add(i,c.getString(4));
i = i + 1;
} } // end - where there is at least 1 record
} finally {
if (c!=null) {
c.close();
} } return port;
}//end getAllTitles()
public void open() {
//Open the database
String myPath = DB_PATH + DATABASE_NAME;
DbLib = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
} }//end class DBAdapter
My Arrival class
package one.two;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class Arrival extends ListActivity
{ private ListView listView;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState)
{ ArrayList<String> retList = new ArrayList<String>();
System.out.println("Start onCreate Function");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.out.println("In onCreate Function");
System.out.println("In of GetData");
DBAdapter db = new DBAdapter(this);
System.out.println("DB Open");
db.open();
System.out.println("DB Opened");
retList = getData();
System.out.println("Out of GetData");
// force count no. of records in table
// dump to check index
int cnt = 2;
int i=0;
for (i = 0; i<cnt; i++)
System.out.println(retList.toString());
listView = (ListView) findViewById(android.R.id.list);
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, android.R.id.list, null, null, null);
this.setListAdapter(mAdapter);
// db.close();
} @SuppressWarnings("static-access")
public static ArrayList<String> getData()
{ ArrayList<String> items = DBAdapter.getAllTitles();
// titles ???? redundant
//ArrayList<String> titles = new ArrayList<String>(items);
System.out.println("Return a LIST titles");
return items;
} }

View 1 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 :: Finalizing Cursor Android.database.sqlite.SQLite­Cursor

May 6, 2009

I am seeing the exception in 'adb logcat'.But I don't know if it is caused by my application or android platform.Can you please give me any idea how to troubleshoot this exception?

View 3 Replies View Related

Android :: Populate A Spinner From Cursor Accessing An SQLite Database?

Aug 25, 2009

How do you populate a spinner from a cursor accessing an SQLite database?

View 2 Replies View Related

Android : Working With SQLite Database / Getting Cursor Out Of Bounds Exception

Jun 30, 2009

I am having some trouble working with the SQLite database. I am able to create the database, add to it, and delete from it with no problem by following the Notepad examples, but I am trying to avoid duplicates and therefore want to check to see if an entry exists already.

Below is the code I have for testing to see if a game exists. I get the correct Log message of "No Games" when there are no games, as well as the correct value for column from getColumnIndex which is proven to me by the log printout telling me that column = 1.

The error message that I receive if I don't catch the exception says "Caused by android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1

Where is Index -1 being requested if my call to getColumnIndex is returning 1? Code...

View 3 Replies View Related

Android :: Add A Data Column To Contacts Db

Aug 6, 2009

Can I add a column of data to the Contacts db, such as birthday, favorite color, whatever. Or does the platform/ framework make this difficult? If possible, would I do it through the contacts content provider?

View 4 Replies View Related

Android :: Determining Data Type Of Column In SQLite

Jun 23, 2010

I'm working on an Android App where the user has different options for sorting the displayed data that comes from the database. Currently my orderBy string that I pass to Androids query() method looks like this:

"LOWER("+columnName+") ASC"

The problem with this is that if the data type in the column specified by columnName is integer, calling LOWER() on it will cause it to be sorted alphabetically, i.e. based only on the leftmost digit, which of course doesn't make any sense for numeric data. Hence I only want to apply LOWER() if the data type of the column is not integer. What I have in mind is a statement like this:

"CASE WHEN [data type of columnName is integer] THEN "+columnName+" ASC ELSE LOWER("+columName+") ASC END"

The part in the brackets is what I don't know how to do. Does SQLite provide a function to determine a column's data type?

View 3 Replies View Related

Android :: Insert Data In To A Single Column Of An Existed Table?

Jul 15, 2010

I have two files, one called "part1.txt" and another one called "part2.txt", which look like following

part1.txt part2.txt
lili like eating apple
lucy like playing football

Now i want to insert the contents of these two files into a single table with the schema

table_name(linefrompart1 varchar(100), linefrompart2 varchar(50))

My program reads the first file line by line and insert the data into the first column. But if it reads the second file and tries to insert the data line by line into the second column, it doesn't work the way i want. A table which i want should look like following

linefrompart1 linefrompart2
lili like eating apple
lucy like playing football

But instead i got the following table

linefrompart1 linefrompart2
lili null
lucy null
null like eating apple
null like playing football

Does somebody know how i can fix this problem?

View 1 Replies View Related

Android :: Android.database.StaleDataExce­ption Access Closed Cursor

May 18, 2010

I have activity A and I used managedQuery in Activity A. I have an adpater which extends from BaseAdapter. In GetView I access the mcursor to get fields.If I click a button on Activity A it goes to B, A---> B.The problem arises when I am in activity B *and it's visible(B), the error is thrown from Acitivity A.I dont understand why I get the error from Activity A. Activity B is visible now and A is in background.There was a post already on this group with similar error but there was no response.I was hoping if someone encountered this and found a solution.

View 2 Replies View Related

Android :: Inserting Data Into Cursor?

Jun 23, 2009

I'm looking for a way to insert data into a cursor that is separate from the SQL database it retrieves the rest of the information from. Is there any way to to this, or is there a different way to add more information to a list view item? What I'm trying to do is to use a date column for each entry in the list to calculate the number of days until that date (and then put that number in the list item). I know how to get the value, but I just cant find a way to put it into the list without it being in the cursor.

View 7 Replies View Related

Android :: Open Helper To Open Database And Get A Cursor To Pass To CursorAdapter

Jul 1, 2010

I have a ListActivity that uses a CursorAdapter to fill the rows in the view. I wrote a database helper class that gives me back results for common queries I make for my app, and it uses an SQLiteOpenHelper implementation I wrote to open the database. I use the open helper to open the database and get a cursor to pass to my CursorAdapter.

Here's a code snippet:

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

The problem I'm having, that I didn't have before I implemented the open helper (before I just opened the database directly without a helper), is when I click on an item, which takes me to another activity, and then go back to this activity. When it initializes everything is fine, and my list is populated fine, but when I go back from the activity that follows, the list is empty and in the LogCat I see "Invalid statement in fillWindow()".

It appears from a few post I've seen that the reason is, when I requery the cursor, the database is closed. But I'm not closing it! I'm scratching my head on this one.

View 2 Replies View Related

Android :: Select Max - Column - Returning Only Column Name

Jul 16, 2010

This has got me all confused! I'm trying to return the max value from a column in my database but the return value is always the name of the column.

The query I use:

private static final String SELECTMAX = "SELECT MAX(?) FROM " + TABLE_NAME ;

The (test) function to return the max value:

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

The column i'm querying is an INTEGER type but the result 's' is always the column name and not the desired value.

View 2 Replies View Related

Android :: How To Retrieve Data From Cursor Class

May 11, 2010

I need to know how to retrieve data from cursor. I need this because the ringtonemanager returns all the audio files in form of cursor object, I need to know how to retrieve the values.

View 2 Replies View Related

Android :: Show Cursor Data In A Listview With Subsection Headings

Feb 3, 2010

I have not found an example yet with a solution to the following task.

I have a SQLite database with two tables- BOOK and AUTHOR. I execute a query on the DB that uses a join and results in a cursor that looks like this. code...

New authors and books can be added to the database at any time, and I also need the user to be able to remove books, hence the [ ] checkboxes.

So i have two row layouts, row_author.xml & row_book.xml. I detect when I need to show a row_author subheading by seeing when the current author has changed compared to the previous row. But I have realized that the rendering of an Author Row will then move the cursor forward one row and jump over their first book.

Can anyone suggest a good approach to presenting data like this? Is there a much better way to do this?

View 2 Replies View Related

Android : Phone Horizontal Scrolling Showing Cursor Data?

Apr 23, 2010

I have some text data in database which I have retrieved in a Cursor, and I am displaying it in a ListView. What I want to do now is that when you select click a particular row in the list its text content should be displayed in full screen and the user should be able to scroll horizontally (like scrolling between iPhone home screens) to view the contents of the Cursor.

View 1 Replies View Related

Android : Can I Create A List Array With Cursor Data In Droid?

Aug 30, 2009

How can I create a list Array (the list display First Alphabet when scroll) with the cursor data?

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

Send Data To Mysql Database - Posted Data Empty

Apr 6, 2014

I send data to my mysql database the posted data is empty...I don't know what is wrong with my code.

[HIGH]urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setDoOutput(true);
urlConnection.setChunkedStreamingMode(0);
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream ());

[Code]...

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 :: Adding Data In A Tree To A ContentProvider

Jun 4, 2010

At the application level, my data is of the form.

* Event
* Contact List
* Contact
* Name
* Email
* Contact
* Name
* Email

The number of contacts is not predefined. Any thoughts on how to push this into a ContentProvider in one go? I basically dont want my application to worry about the hierarchy and bulk insert or something, I want to hand this responsibility over to the ContentProvider.

View 2 Replies View Related







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