| Author |
Message |
Katharnavas Senior Developer
Joined: 04 Dec 2007 Posts: 100 Location: India
|
Posted: Wed Feb 20, 2008 10:45 am Post subject: |
|
|
| Sportsdude11751 wrote: | The source code I used was plusminus's source. I will copy and paste it next time I can get on that computer.
Even if it can't find the database, in +-'s source he had a create database statement. |
For you i tried the same database code with M5 version and it worked perfectly for me. Did you checked from the command line. |
|
| Back to top |
|
 |
königdmx Junior Developer
Joined: 19 Feb 2008 Posts: 13
|
Posted: Wed Feb 20, 2008 1:41 pm Post subject: |
|
|
hi,
for the part of output i received an error on compilation:
| Java: |
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, results));
|
eclipse meaning "setListAdapter" = "The method setListAdapter(ArrayAdapter<String>) is undefined for the type createDB"
What can i do instead of this? |
|
| Back to top |
|
 |
Katharnavas Senior Developer
Joined: 04 Dec 2007 Posts: 100 Location: India
|
Posted: Wed Feb 20, 2008 1:54 pm Post subject: |
|
|
| königdmx wrote: | hi,
for the part of output i received an error on compilation:
| Java: |
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, results));
|
eclipse meaning "setListAdapter" = "The method setListAdapter(ArrayAdapter<String>) is undefined for the type createDB"
What can i do instead of this? |
What i think is some header files are being missed. use Shift+Ctrl O and it will solve the problem. |
|
| Back to top |
|
 |
königdmx Junior Developer
Joined: 19 Feb 2008 Posts: 13
|
Posted: Wed Feb 20, 2008 2:48 pm Post subject: |
|
|
@Katharnavas: thx for reply, but it didn´t help me. The error is the same..
these are the imports:
| Java: |
import java.io.FileNotFoundException;
import java.util.ArrayList;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ArrayAdapter; |
The problem: when i enter the code completion do not offer me |
|
| Back to top |
|
 |
plusminus Site Admin

Joined: 14 Nov 2007 Posts: 2102 Location: Germany
|
Posted: Wed Feb 20, 2008 3:49 pm Post subject: |
|
|
Hello königdmx,
is your class extending ListActivity
Looks like you are extending just Activity.
Regards,
plusminus _________________
| Android Development Community / Tutorials |
|
| Back to top |
|
 |
königdmx Junior Developer
Joined: 19 Feb 2008 Posts: 13
|
Posted: Wed Feb 20, 2008 3:56 pm Post subject: |
|
|
yepp, thats it!
thx!! |
|
| Back to top |
|
 |
cabernet1976 Senior Developer
Joined: 16 Nov 2007 Posts: 147 Location: China
|
Posted: Wed Feb 27, 2008 3:10 pm Post subject: |
|
|
Hi all,
The new method | Java: | public Cursor rawQuery(String sql, String[] selectionArgs) | seems able to replace the previous method query, but Eclipse cannot distinguish rawQuery and says it is undifined.
I don't know why. _________________ EveryAlbum - http://www.anddev.org/viewtopic.php?p=7117#7117 |
|
| Back to top |
|
 |
res Senior Developer
Joined: 20 Nov 2007 Posts: 147 Location: United States
|
Posted: Wed Mar 05, 2008 5:22 pm Post subject: |
|
|
| cabernet1976 wrote: | Hi all,
The new method | Java: | public Cursor rawQuery(String sql, String[] selectionArgs) | seems able to replace the previous method query, but Eclipse cannot distinguish rawQuery and says it is undifined.
I don't know why. |
Make sure you have updated Eclipse to point to the new m5 sdk directory. |
|
| Back to top |
|
 |
MobileBen Freshman
Joined: 20 Mar 2008 Posts: 4
|
Posted: Thu Mar 20, 2008 4:16 am Post subject: Select statement |
|
|
Hello everyone,
I read the post today (Its the first time I am here in this forum) and it helped me very much. Thx
But I have a question to the rawQuery.
How can I make a "Select statement" like it was done befor (the example from plusminus) with this query?
Can anybody give me a code example, because Android always crys, doesn't matter what I d
Thx guys |
|
| Back to top |
|
 |
mill Once Poster
Joined: 29 Mar 2008 Posts: 1 Location: Malaysia
|
Posted: Sat Mar 29, 2008 5:56 pm Post subject: startManagingCursor(cursor) |
|
|
Hi plusmimus, I see you did not use startManagingCursor(cursor) in your code, will it cause any issue?
How do I call startManagingCursor(cursor) in a IntentReceiver or in a Service ?
Thanks |
|
| Back to top |
|
 |
plusminus Site Admin

Joined: 14 Nov 2007 Posts: 2102 Location: Germany
|
Posted: Sat Mar 29, 2008 7:31 pm Post subject: Re: startManagingCursor(cursor) |
|
|
Hello mill,
| mill wrote: | Hi plusmimus, I see you did not use startManagingCursor(cursor) in your code, will it cause any issue?
How do I call startManagingCursor(cursor) in a IntentReceiver or in a Service ? |
| Quote: | | This method allows the activity to take care of managing the given Cursor's lifecycle for you based on the activity's lifecycle. That is, when the activity is stopped it will automatically call deactivate() on the given Cursor, and when it is later restarted it will call requery() for you. |
It is not needed, but would be nicer, yes.
I'm not sure, but IntentReceivers last only 'one call' and Services last 'forever' without being really stopped...
Regards,
plusminus _________________
| Android Development Community / Tutorials |
|
| Back to top |
|
 |
NithinG Developer
Joined: 27 Feb 2008 Posts: 30
|
Posted: Wed Apr 16, 2008 3:11 pm Post subject: |
|
|
Hi plus minus,
I faced a problem while creating database. The problem is.
I am creating a database in a class which extends activity, and that is defined in a function.
This function i have to call from another class which doesnt extent activity( normal class ).
So i am not able to give context value. So i am not able to create constructor(Context ctx) also.
So while running its giving and Exception :- java.lang.RuntimeException: Not supported in system context
if this is the case what can i do?
Can you pease help me to solve this problem.
Thanks and regards,
NithinG |
|
| Back to top |
|
 |
lmsa Freshman
Joined: 21 Apr 2008 Posts: 3
|
Posted: Mon Apr 21, 2008 4:50 pm Post subject: Display DB |
|
|
Hy PlusMinus,
I'm working on Android's DB and I've a problem for the output of my DB.
I don't know how to display it.
I give you my source code I hope you can help me.
| Java: |
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
class Contact extends Object {
public long contactId;
public String phone;
public String name;
}
public class DroidDB {
private static final String CREATE_TABLE_CONTACTS = "create table contacts (contact_id integer primary key autoincrement, "
+ "phone text not null, name text not null);";
private static final String CONTACTS_TABLE = "contacts";
private static final String DATABASE_NAME = "newdroid";
private static final int DATABASE_VERSION = 1;
private SQLiteDatabase db;
public DroidDB(Context ctx) {
try {
db = ctx.openDatabase(DATABASE_NAME, null);
} catch (FileNotFoundException e) {
try {
db = ctx.createDatabase(DATABASE_NAME, DATABASE_VERSION, 0,
null);
db.execSQL(CREATE_TABLE_CONTACTS);
} catch (FileNotFoundException e1) {
db = null;
}
}
}
public boolean insertContact(String phone, String name) {
ContentValues values = new ContentValues();
values.put("phone", phone);
values.put("name", name.toString());
return (db.insert(CONTACTS_TABLE, null, values) > 0);
}
public boolean deleteContact(Long contactId) {
return (db.delete(CONTACTS_TABLE, "contact_id=" + contactId.toString(), null) > 0);
}
public List<Contact> getContacts() {
ArrayList<Contact> contacts = new ArrayList<Contact>();
try {
Cursor c = db.query(CONTACTS_TABLE, new String[] { "contact_id", "phone",
"name" }, null, null, null, null, null);
int numRows = c.count();
c.first();
for (int i = 0; i < numRows; ++i) {
Contact contact = new Contact();
contact.contactId = c.getLong(0);
contact.phone = c.getString(1);
contact.name = new String(c.getString(2));
contacts.add(contact);
c.next();
}
} catch (SQLException e) {
Log.e("NewsDroid", e.toString());
}
return contacts;
}
}
|
Cordialy,
lmsa |
|
| Back to top |
|
 |
bjreddi Junior Developer
Joined: 03 Apr 2008 Posts: 17
|
Posted: Mon Apr 28, 2008 11:51 am Post subject: |
|
|
Hi,
Instead of using
myDb.query()
use
myDb.rawQuery(); |
|
| Back to top |
|
 |
E.Jyothsna Junior Developer
Joined: 28 Feb 2008 Posts: 22 Location: chennai
|
Posted: Tue Apr 29, 2008 2:10 pm Post subject: |
|
|
in my application i am having spinner.I am setting the values and i stored in database and again i am retreving the values from database.upto this ok.how to set the retreving values to spinner?for example from spinner i selected 25MInutes and i came from that application to another application.Again if i go to that previous application and if i see that spinner it should be my selected item that means 25Minutes.But it is showing default values.How can i solve this problem?I want immediate response.Plz soon give me reply.
This is my code:i created database and my table in another file but same application
| Java: | public class Preferences extends Activity {
private String res;
private long timeid;
private SQLiteDatabase myDatabase;
private String serviceInterval;
private String getservicerequestinterval;
private String TimeInterval;
private String getmStuffView;
private String MStuffView;
private String time;
private String views;
private String viewname1;
private String servicename1;
private String timename1;
final ArrayList<CharSequence> results = new ArrayList<CharSequence>();
RadioButton mStuffView;
RadioButton mStufftext;
RadioButton servicerequestinterval;
RadioButton servicerequestmanual;
Spinner timeinterval;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.preferences);
try {
myDatabase = this.openDatabase("Mobeegal", null);
String[] col = {"views", "service", "time"};
Cursor c = myDatabase.query(true, "Preferences", col, null, null, null, null, null);
int viewname = c.getColumnIndex("views");
int servicename = c.getColumnIndex("service");
int timename = c.getColumnIndex("time");
if (c != null) {
if (c.first()) {
do {
viewname1 = c.getString(viewname);
servicename1 = c.getString(servicename);
timename1 = c.getString(timename);
results.add(viewname1);
results.add(servicename1);
results.add(timename1);
} while (c.next());
}
}
res = results.toString();
Toast.makeText(Preferences.this, timename1, Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException e) {
}
TabHost tabs = (TabHost) this.findViewById(R.id.tabs);
tabs.setup();
TabHost.TabSpec one = tabs.newTabSpec("one");
one.setContent(R.id.mStuffView);
one.setIndicator("mStuffView");
tabs.addTab(one);
mStuffView = (RadioButton) findViewById(R.id.mapviewradiobutton);
mStufftext = (RadioButton) findViewById(R.id.textviewradiobutton);
if (viewname1.toString().equals("MapView")) {
mStuffView.setChecked(true);
mStufftext.setChecked(false);
} else {
mStufftext.setChecked(true);
mStuffView.setChecked(false);
}
TabHost.TabSpec two = tabs.newTabSpec("two");
two.setContent(R.id.servicerequestinterval);
two.setIndicator("Service request interval");
tabs.addTab(two);
timeinterval = (Spinner) findViewById(R.id.timeinterval);
timeinterval.setVisibility(View.INVISIBLE);
servicerequestinterval = (RadioButton) findViewById(R.id.autoradiobutton);
servicerequestmanual = (RadioButton) findViewById(R.id.manualradiobutton);
// servicerequestinterval.setChecked(true);
if (servicename1.toString().equals("Auto")) {
servicerequestinterval.setChecked(true);
servicerequestmanual.setChecked(false);
timeinterval = (Spinner) findViewById(R.id.timeinterval);
timeinterval.setVisibility(View.INVISIBLE);
} else {
servicerequestmanual.setChecked(true);
servicerequestinterval.setChecked(false);
timeinterval = (Spinner) findViewById(R.id.timeinterval);
timeinterval.setVisibility(View.VISIBLE);
if (TimeInterval != timename1) {
// // Toast.makeText(Preferences.this, TimeInterval, Toast.LENGTH_SHORT).show();
timeinterval.setDrawSelectorOnTop(true);
timeinterval.setVisibility(1);
} else {
timeinterval.setVisibility(View.VISIBLE);
// Toast.makeText(Preferences.this, TimeInterval, Toast.LENGTH_SHORT).show();
}
}
ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(
this, R.array.timeperiod, android.R.layout.simple_spinner_item);
timeinterval.setAdapter(adapter1);
timeinterval.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView parent, View v,
int position, long id) {
TimeInterval = (String) timeinterval.getSelectedItem();
// timeid = timeinterval.getSelectedItemId();
}
public void onNothingSelected(AdapterView parent) {
}
});
final RadioButton manualRadiobutton = (RadioButton) findViewById(R.id.manualradiobutton);
if (manualRadiobutton.isEnabled()) {
manualRadiobutton.setOnClickListener(new RadioButton.OnClickListener() {
public void onClick(View arg0) {
timeinterval.setVisibility(View.VISIBLE);
}
});
}
final RadioButton autoRadiobutton = (RadioButton) findViewById(R.id.autoradiobutton);
if (autoRadiobutton.isEnabled()) {
autoRadiobutton.setOnClickListener(new RadioButton.OnClickListener() {
public void onClick(View arg0) {
timeinterval.setVisibility(View.INVISIBLE);
}
});
}
tabs.setCurrentTab(0);
final Button savebutton = (Button) findViewById(R.id.save);
savebutton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
mStuffView = (RadioButton) findViewById(R.id.mapviewradiobutton);
if (mStuffView.isChecked()) {
getmStuffView = "MapView";
} else {
getmStuffView = "TextView";
}
servicerequestinterval = (RadioButton) findViewById(R.id.autoradiobutton);
if (servicerequestinterval.isChecked()) {
getservicerequestinterval = "Auto";
} else {
getservicerequestinterval = "Manual";
}
myDatabase.execSQL("UPDATE Preferences set views='" + getmStuffView + "',service='" + getservicerequestinterval + "',time='" + TimeInterval + "' where preference=preference");
Toast.makeText(Preferences.this, "Change Setting Activated", Toast.LENGTH_SHORT).show();
}
});
}
// MenuView
@Override
public boolean onCreateOptionsMenu(Menu menu) {
ViewMenu viewmenu = new ViewMenu();
viewmenu.onCreateOptionsMenu(menu);
return true;
}
// Menu Item
@Override
public boolean onOptionsItemSelected(Item item) {
switch (item.getId()) {
// mStuff Menu
case 1:
Intent stuffCheckintent = new Intent(Preferences.this, MstuffMapView.class);
startActivity(stuffCheckintent);
break;
case 2:
Intent intent1 = new Intent(Preferences.this, FindandInstall.class);
startActivity(intent1);
break;
case 3:
Intent settings = new Intent(Preferences.this, Settings.class);
startActivity(settings);
break;
}
return super.onOptionsItemSelected(item);
}
} |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
© 2007, Android Development Community
All rights reserved.
Powered by phpBB.
|