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;
} }

Android :: How to Import Cursor from Database Class into Current One?


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 :: How Do Import A Java Point Class

Sep 17, 2009

I am writing an android game. I need a Point class that stores x and y coordinates. I have found a class called java.awt.Point. Which looks like what I need. I have created an interface for java.awt.Point and put import java.awt.Point in my code. But when I do Point pos = new Point.

I get an error: cannot instantiate Point. Also if I do pos. I don't get x or y member variables. I could code my own Point class but I need to learn how to import stuff.

If I delete the interface for Point I get an error on import java.awt.Point. It says the import cannot be resolved.

View 4 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 :: Full Android Database Class For Existing SQLite Database?

Aug 23, 2010

I'm trying to deploy an application with an existing SQLite database.I've been reading though the examples that are posted but they are always missing some part of the class. I feel like I'm trying to bake muffins but no one told me to use baking powder.Can someone post a full database helper class for depoying an SQLite database on Android? Edit : Delete old code because it doesn't work.

View 2 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 :: Database Errors While Import Content Values

Nov 3, 2009

I been working on this code dealing with my database for days i can figure out whats wrong. Heres my code: package com.helpihelpyou;

import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.net.Uri; import android.provider.Contacts.People; import android.util.Log;
import java.util.ArrayList; import java.util.List;

public class HelpiDB {...........................

View 2 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 :: Way To Refactor Current Code To Add Database Feature?

May 22, 2010

I am adding a local database as a cache to a remote web service in my android application to answer queries. I used ArrayAdapters before for list views to display the results from the web service. Now with a database cache, the result could be either a Cursor(from database) or a List(from web), which means the adapter can be CursorAdapter or ArrayAdapter too. Creating two adapters for one query doesn't seem to be a good idea. So I am wondering what would be the best way to refactor my current code to add this database feature?

View 1 Replies View Related

Android :: Static Database Class To Use With Any Activity

Jan 5, 2010

I am new to Android, and I haven't developed any app regarding databases on Android yet. So I have a few basic questions. I am after a good database class sample, that will let me to run the CRUD operations. I would like to use it as a static class

like: clsDB->Select("select * from clients");
or objClient->Delete(clientid);

I am wondering if someone, can share his database classes, if more people share the best. Also I have in mind to reuse this class in multiple ways, I will have services, activities etc...

View 4 Replies View Related

Android :: Utility Class For Database Query

Sep 23, 2009

Can anybody suggest what functionality to provide in a query utility class/classes? The idea is to provide a database utility package for android developers. I just wanna do it for android community and of course for my learning.:-)

View 5 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 :: Cannot Open Database In Service Layer Class

Sep 15, 2010

When I create a instance of the SQLiteOpenHelper, I always need a "Context" to be passed as its constructor's argument. To use this "Context", in my service layer class, I extends Activity class, though I do not display this activity on the screen because it is my service layer. I always get NullPointer exception when I open the SQLiteOpenHelper in my service layer class, Is it because my service layer class extends the Activity class but I did not show this activity on mobile screen? (That's there is no intent to my service layer class), if it is so, how to get rid of it if I wanna open a SQLiteOpenHelper in my service layer class which do not need to extends Activity, but need a Context object to pass to SQLiteOpenHelper?

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

View 2 Replies View Related

Android :: Android - Use One SQLiteOpenHelper Class For Multiple Database Files

Nov 20, 2010

My app uses two databases (separate files). To handle these databases I have created two Helper classes which extend SQLiteOpenHelper, one for each database.

I am now going to add a third database and wonder whether I need to create yet another Helper class (and if I used a 4th and a 5th database would I need even more Helper classes), or can I use the same Helper class for multiple databases?

The problem that I see with trying to use just one Helper class is that I can't see how to pass the name of the individual database files to the Helper. At present the name of the database is hard-coded as a Static field of each of the Helper classes, but if I had only one Helper class I would need to be able to pass the different names in to the Constructor when creating the separate Helper objects; the problem is that the SQLiteOpenHelper Constructor seems to be called by Android with just one parameter: the Context.

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 :: Unable To Import Import Com.google.android.gtalkservic­e.IGTalkSession

Apr 16, 2010

I am implementing GTalk sample application by refering some book But they mentioned the following imports import

com.google.android.gtalkservice.IGTalkSession; import com.google.android.gtalkservice.IGTalkService; import com.google.android.gtalkservice.GTalkServiceConstants; import com.google.android.gtalkservice.IChatSession;

But when i am importing it is giving me error the import can't be resolved. I tried those above imports for the following targets 1.1, 1.5, Google api, 1.6.Google api, 2.0, Google api, 2.0.1,Google api, 2.1, Google api No where the above imports found I am unable to import above things.

View 2 Replies View Related

Android :: Blocking Current Activity / Screen Till Current Task Is Complete

May 13, 2010

The default behavior of an activity when BACK softkey is pressed is, GO BACK TO PREVIOUS ACTIVITY. If some the same activity is waiting for some response from server or some data updation is going on and then press BACK, I want to wait on the same screen till the current task is completely processed and then move out to the previous activity.

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+unsubscribe@googlegroups.com For more options

View 12 Replies View Related

Android :: Creating A New Class Using Eclipse New Java Class Dialog Box

Jul 7, 2010

I'm creating a new class, using eclipse "New Java Class" dialog box. I can write the superclass I want (I can't find using "browse" button), but I can't write or select an interface to implement. I click "add" but ther is nothing to select. What I'm doing wrong?

View 4 Replies View Related

Android :: Communicating Between Receiver Class And An Activity Class

Jul 14, 2010

I'm just getting into Android development, and I have a question about communicating between a receiver class and an activity class. I'm very new to JAVA and Android so I hope I don't sound too stupid. I'm developing an application where I intercept an SMS message and then based on various elements of that SMS I might delete it once it's been saved to the inbox. I have a receiver class that intercepts the txt message, and I am also able to delete messages from my inbox with code in the activity class using a button at the moment. The problem I have is communicating between the receiver class and the activity class where the code to delete a message resides. I tried putting that code directly into the receiver class but as I'm sure most of you already know the BroadcastReceiver class doesn't seem to support what I need to delete messages. I've been searching for an answer to this for a while, but haven't been able to find anything. Honestly I'm not sure I know enough about JAVA and Android to even recognize a solution if I saw it.

View 2 Replies View Related

Android :: Accessing Class Level Stuff From Inner Class

Jun 27, 2010

What I want to do, is be able to access the object neoApi inside the Neoseeker class, from its inner class RunningTimer. Now, in my code, you can see what I would think to work, but when I run my application, nothing pops up. Nothing inside my TextView, no Toast, nothing at all. How can I remedy this?

package com.neoseeker.android.app;
import java.util.Timer;
import java.util.TimerTask;
import org.json.JSONObject;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;.......................

View 1 Replies View Related

Android :: Access Application Class From Class Other Then Activity

Sep 8, 2010

I'm new to Java and android development. In my application I need data which is accessible for a few activities. I've read that a good solution is to use Application class for this. So I use it like this:

public class MyApplication extends Application {
private String str;
public String getStr(){
return str;
}
public void setStr(String s){
str = s;
}
}

and I can access this variable from activity like this:........................................

View 2 Replies View Related

Android :: Call Activity Class From Other Java Class?

Oct 8, 2010

I have just started android. I just want to know that how can i call activity class from other java class. i just want to pass class object to activity class.

public class GsonParser extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MagazineThread thread=new MagazineThread();
thread.start();
}
public GsonParser(JsonMagazineParser Obj)
{

}
}

and i am just doing like from other class. GsonParser obj=new GsonParser(this);passing obj to activity class.how can i achieve that.

View 1 Replies View Related

Android :: How To Run Class In Background Among Package Of Class?

Apr 23, 2010

In my app in one package there are some classes. from those classes i want to run one class that is the Gps functionality class. i want to run that class in background. how i do it, i don't know. i am not able to make it solve from any document. if anybody knows the way to solve it please me by run a "hello world" app in the background. i am not able to solve this problem by going through document.

View 2 Replies View Related

Android :: In Java, What Does A Reference To Class.class Do?

Jul 20, 2010

I'm building a small Android application, but this is more of a Java question than an android question. Looking through the tutorials there are lines that look like: startService(new Intent(this, MyService.class));

What exactly does the "MyService.class" field represent? Is that just a reference to the class for a template?

View 4 Replies View Related

Android :: Dialog Class With It's View Class?

May 19, 2009

I made a Dialog Class with it's view classI want to pop up the dialog when I got some packets from network. so I made a Thread which parses packets and then I made if clause in Run() method There is no problem with parsing packet but when I enter "if clause" and call showDialog() I got Error message

Is there anyone who knows how to pop up a dialog from different thread?

View 2 Replies View Related







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