I already did my code based on WIllJBD's suggestion
I want the table refresh the data when its clicked according to spinner, but my toast gave "Database Error". Here is the code for the selected item on spinner
public void onItemSelected(AdapterView<?> parent, View view, int position,long id) {
String tam = spDealer.getSelectedItem().toString();
String dealerID = in.getDealID(tam);
String queryrow = in.MatchDealerID(dealerID);
if (queryrow == dealerID)
{
Cursor c = in.getViewInfoBilling(queryrow);
int rows = c.getCount();
int cols = c.getColumnCount();
c.moveToFirst();
for (int i = 0; i < rows; i++) {
TableRow row = new TableRow(this);
row.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
// inner for loop
for (int j = 0; j < cols; j++)
{
TextView tv = new TextView(this);
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
tv.setText(c.getString(j));
row.addView(tv);
}
c.moveToNext();
mytable.addView(row);
}
in.close();
} else
{
Toast.makeText(Billing.this, "Data Error!!",Toast.LENGTH_LONG).show();
}
}
And here is my method:
public Cursor getViewInfoBilling(String id){
Cursor mcursor = db.rawQuery("SELECT BillDate,SODashboardNo, SODashboardAmount " +
"FROM SODashboard, Bill WHERE SODashboard.SODashboardNo = Bill.TampSODashboardNo " +
"AND SODashboard.DealerID = id", null);
return mcursor;}
public String getDealID(String dealName) throws SQLException{
Cursor mCursor = db.query(Dealer_TABLE, null, ""+Col_DealerName+"=?", new String[]{dealName}, null, null,null);
if(mCursor.getCount()<1){
mCursor.close();
return "Not Exist";
}
mCursor.moveToFirst();
String tampDealID = mCursor.getString(mCursor.getColumnIndex(Col_DealerID));
mCursor.close();
return tampDealID;}
public String MatchDealerID(String tam){
String matchquery = "SELECT DealerID FROM SODashboard, Dealer " +
"WHERE SODashboard.TampDealerIDSOD = tam";
return matchquery;
}
Isnt the ID selected on spinner already same with the ID thats on DB? I already created MatchDealerID and getDealID to compare them.. what should I do make the table refreshes after clicked? Please help me to solve this issue... thank you
There is something wrong in this method.
public Cursor getViewInfoBilling(String id){
Cursor mcursor = db.rawQuery("SELECT BillDate,SODashboardNo, SODashboardAmount " +
"FROM SODashboard, Bill WHERE SODashboard.SODashboardNo = Bill.TampSODashboardNo " +
"AND SODashboard.DealerID =" + id, null);
//OR
/*
Cursor mcursor = db.rawQuery("SELECT BillDate,SODashboardNo, SODashboardAmount " +
"FROM SODashboard, Bill WHERE SODashboard.SODashboardNo = Bill.TampSODashboardNo " +
"AND SODashboard.DealerID =?", new String[] { id });
*/
return mcursor;}
There are two versions , try both , have good luck
Related
I have a code that would give me the sum of a column in a database, i have done the crud, but now i would like to do a search by a the name of a column and show the sum of all the records(that have the same name) and show in a textfield.
the following is my DatabasdeHandler:
public Cursor getSingleDespesaSum(String date) {
SQLiteDatabase db = this.getReadableDatabase();
int sum = 0;
Cursor cursor = db.rawQuery(
"select sum(valor) from despesas WHERE data = ?", null);
if (cursor.moveToFirst()) {
do {
sum = cursor.getInt(0);
} while (cursor.moveToNext());
}
return cursor;
}
And this is my activity;
btGetSum.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
try {
dia = (String) spinDia.getSelectedItem();
mes = (String) spinMes.getSelectedItem();
ano = (String) spinAno.getSelectedItem();
String dataSendTo = dia + "/" + mes + "/" + ano;
dbhelper.getSingleDespesaSum(dataSendTo); //missing code
} catch (Exception erro) {
mensagemExibir("Erro Ao Buscar", "" + erro.getMessage());
}
}
});
}
Content Providers are the way to go, don't access your database directly like this.
But... to answer your current question:
SQLiteDatabase db = this.getReadableDatabase();
int sum = 0;
Cursor cursor = db.rawQuery(
"select value from table WHERE date= ?", null);
while (cursor.moveToNext()) {
//Increment your counter
sum += cursor.getInt(cursor.getColumnIndex("value");
};
Am trying to create dynamic checkboxes based on contents of two tables. I am able to create the checkboxes but the problem comes on the OnCheckedChangeListener where i cant pick the index of the clicked checkbox. Below is my code. Any assistance is highly appreciated
I call getViews() on the onCreate() Method
public void getViews(){
// TableLayout ref from xml where we want to Display list
final TableLayout proF = (TableLayout) findViewById(R.id.TableLayout_views);
// Get the database and run the query
final SQLiteDatabase datb = mDatabase.getWritableDatabase();
Cursor curs = datb.rawQuery("SELECT * FROM " + tarea.AREA_TABLE_NAME
+ " WHERE " + tarea.AREA_ID + " LIKE '" +"1"+ "' ", null);
curs.moveToFirst();
if (curs.getCount() > 0) {
for (int i = 0; i < curs.getCount(); i++) {
area_id = curs.getInt(curs.getColumnIndex(tarea.AREA_ID));
curs.moveToNext();
}
}
System.out.println("Area Id is : " + area_id);
Cursor cur = datb.rawQuery("SELECT * FROM " + tclass.CLASS_TABLE_NAME
+ " WHERE " + tclass.CLASS_AREA_ID + " LIKE '" +area_id+ "' ", null);
cur.moveToFirst();
clss = new String[cur.getCount()];
if (cur.getCount() > 0) {
int i ;
for (i = 0; i < cur.getCount(); i++) {
clss[i] = cur.getString(cur.getColumnIndex(tclass.CLASS_ITEM));
System.out.println("Class item : " + clss[i]);
class_id = cur.getInt(cur.getColumnIndex(tclass.CLASS_ID));
System.out.println("Class Id is : " + class_id);
Cursor c = datb.rawQuery("SELECT * FROM " + tmonitoring.MONITORING_TABLE_NAME
+ " WHERE " + tmonitoring.MONITORING_CLASS_ID + " LIKE '" +class_id+ "' ", null);
c.moveToFirst();
avail = new CheckBox[cur.getCount()][c.getCount()];
edtbox = new EditText[cur.getCount()][c.getCount()];
System.out.println("cur.getCount()>>" + cur.getCount());
System.out.println("c.getCount()>>" + c.getCount());
System.out.println("avail.length >> "+avail.length);
// class Dynamic table
TableRow RowArea = new TableRow(this);
TableRow tRow = new TableRow(this);
TableRow items = new TableRow(this);
int color = getResources().getColor(R.color.font_color_bg);
int color2 = getResources().getColor(R.color.font_color_white);
TextView tResult = new TextView(this);
tResult.setText("MON ITEM");
tResult.setTextColor(color2);
TextView tResult1 = new TextView(this);
tResult1.setText("_____________");
tResult1.setTextColor(Color.rgb(255, 106, 0));
TextView tResults = new TextView(this);
tResults.setText("RESULT");
tResults.setTextColor(color2);
TextView tResult2 = new TextView(this);
tResult2.setText("____________");
tResult2.setTextColor(Color.rgb(255, 106, 0));
TextView tResults1 = new TextView(this);
tResults1.setText("ACTION");
tResults1.setTextColor(color2);
TextView tResults2 = new TextView(this);
tResults2.setText("____________");
tResults2.setTextColor(Color.rgb(255, 106, 0));
TextView tResults3 = new TextView(this);
tResults3.setText("ACTION");
tResults3.setTextColor(color2);
TextView tResult3 = new TextView(this);
tResult3.setText("____________");
tResult3.setTextColor(Color.rgb(255, 106, 0));
TextView AreaResults = new TextView(this);
AreaResults.setBackgroundColor(color);
AreaResults.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL);
AreaResults.setTextColor(color2);
AreaResults.setText(clss[i]);
RowArea.addView(AreaResults);
tRow.addView(tResult);
items.addView(tResult1);
tRow.addView(tResults);
items.addView(tResult2);
tRow.addView(tResults1);
items.addView(tResults2);
tRow.addView(tResults3);
items.addView(tResult3);
proF.addView(RowArea);
proF.addView(tRow);
proF.addView(items);
if (c.getCount() > 0) {
int j;
for (j = 0; j < c.getCount(); j++) {
System.out.println("Monitoring item : " + c.getString(c.getColumnIndex(tmonitoring.MONITORING_ITEM)));
TableRow newRow = new TableRow(this);
newRow.setGravity(Gravity.CENTER);
newRow.setTag(c.getString(c.getColumnIndex(tmonitoring.MONITORING_CLASS_ID)));
// column 1 mon item
TextView nameCol = new TextView(this);
nameCol.setWidth(20);
nameCol.setMaxWidth(8);
nameCol.setTypeface(nameCol.getTypeface(), Typeface.BOLD);
nameCol.setText(" " + c.getString(c.getColumnIndex(tmonitoring.MONITORING_ITEM)));
//column 2 checkbox
CheckBox chkbox = new CheckBox(this);
chkbox.setId(j);
chkbox.setText("Yes");
avail[i][j] = chkbox;
System.out.println("avail["+i+"]["+j+"]>> " + chkbox);
System.out.println("avail id->" + avail[i][j].getId());
avail[i][j].setOnCheckedChangeListener(checkListener);
//column 3 take pic
Button picCol = new Button(this);
picCol.setText("Take Pic");
picCol.setTag(c.getInt(c.getColumnIndex(tmonitoring.MONITORING_CLASS_ID)));
picCol.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
SQLiteDatabase db = mDatabase.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM "
+ shelfImage.IMAGE_TABLE_NAME + ";", null);
if (cursor.getCount() > 25) {
Log.v(TAG, "Alert SRR to upload data");
AlertDialog al = showAlertUpload();
al.show();
} else {
Intent myIntent = null;
myIntent = new Intent(Design_Template1.this, Capturephoto.class);
Bundle bund = new Bundle();
bund.putInt("r", r);
bund.putString("user", name);
bund.putInt("userid", userid);
bund.putString("dealer", dealer);
bund.putString("week", weekno);
bund.putString("ticket", Ticket);
bund.putString("picArray", picArray);
myIntent.putExtras(bund);
Design_Template1.this.startActivityForResult(myIntent, 0);
}
cursor.close();
db.close();
}
});
// column 4 view pic
Button viewCol = new Button(this);
viewCol.setText("View Guideline");
viewCol.setTag(c.getInt(c.getColumnIndex(tmonitoring.MONITORING_CLASS_ID)));
viewCol.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Integer id = (Integer) v.getTag();
}
});
newRow.addView(nameCol);
newRow.addView(chkbox);
newRow.addView(picCol);
newRow.addView(viewCol);
proF.addView(newRow);
c.moveToNext();
}
}
c.close();
cur.moveToNext();
}
}
curs.close();
cur.close();
datb.close();
}
My click listener is as below
private OnCheckedChangeListener checkListener = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
// Test avail Checkbox
StringBuffer r = new StringBuffer();
int clss;
db1 = mDatabase.getReadableDatabase();
System.out.println("area_id on click listener : " + area_id);
Cursor cur = db1.rawQuery("SELECT * FROM " + tclass.CLASS_TABLE_NAME
+ " WHERE " + tclass.CLASS_AREA_ID + " LIKE '" +area_id+ "' ", null);
cur.moveToFirst();
for(int i = 0; i < cur.getCount(); i++){
clss = cur.getInt(cur.getColumnIndex(tclass.CLASS_ID));
System.out.println("Classid on click listener : " + clss);
results = db1.rawQuery("SELECT "+tmonitoring.MONITORING_ITEM+" FROM " + tmonitoring.MONITORING_TABLE_NAME
+ " WHERE " + tmonitoring.MONITORING_CLASS_ID + " LIKE '" +clss+ "' ", null);
for (int u = 0; u < results.getCount(); u++) {
if (avail[u] != null) {
r.append("\nResults->" + u + " : ").append(
avail[i][u].isChecked());
}
}
cur.moveToNext();
}
cur.close();
results.close();
db1.close();
}
};
The part where i check if isChecked() throws ArrayIndexOutOfBoundsException. Please help
setting the tag will help you to recognize the created checkbox on later stage.
avail = new CheckBox[cur.getCount()][c.getCount()];
avail.setTag(i);//add this line
And inside
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
Integer i=(Integer)buttonView.getTag();
above line gets the checkbox on which the check/uncheck event is performed.
this way you would be able to find out the index.
I have a method named getData that populates a listView from my database limited to specified columns from the table:
public ArrayList<String> getData() {
// TODO Auto-generated method stub
String[] columns = new String[] { KEY_ROWID, KEY_MODULE_CODE,
KEY_MODULE_NAME, KEY_LECTURE_PRACTICAL,
KEY_LECTURE_PRACTICAL_SHORT, KEY_LECTURE_DAY,
KEY_LECTURE_DAY_SHORT, KEY_START_TIME, KEY_END_TIME,
KEY_LOCATION, ADDITIONAL_INFO };
Cursor c = ourDatabase.query(DATABASE_MODULES, columns, null, null,
null, null, null);
ArrayList<String> results = new ArrayList<String>();
int indexModCode = c.getColumnIndex(KEY_MODULE_CODE);
int indexLectPracShort = c.getColumnIndex(KEY_LECTURE_PRACTICAL_SHORT);
int indexLectDayShort = c.getColumnIndex(KEY_LECTURE_DAY_SHORT);
int indexLectStart = c.getColumnIndex(KEY_START_TIME);
int indexLectLoc = c.getColumnIndex(KEY_LOCATION);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
results.add(c.getString(indexModCode) + " "
+ c.getString(indexLectPracShort) + " "
+ c.getString(indexLectDayShort) + " "
+ c.getString(indexLectStart) + " "
+ c.getString(indexLectLoc));
}
return results;
}
This works fine and here is how I populate my listview (ModuleDatabaseHandler is the class where the database is managed):
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_modules_test);
ModuleDatabaseHandler info = new ModuleDatabaseHandler(this);
info.open();
ArrayList<String> data = info.getData();
info.close();
l = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 ,data);
l.setAdapter(adapter);
l.setOnItemClickListener(this);
}
I want to be able to click the listView item, and view ALL the information pertaining to the record (in the listView it only shows certain information). I have attempted to create a new method in the ModuleDatabaseHandler class called getAllData.
Below is the OnItemClick for the ListView item which launches a new activity, passing through the information from getAllData using putExtra:
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
TextView temp = (TextView) view;
Toast.makeText(this, temp.getText() + " " + i, Toast.LENGTH_SHORT)
.show();
ModuleDatabaseHandler info = new ModuleDatabaseHandler(this);
info.open();
String module_info = info.getAllData(); // METHOD TO GET ALL DATA
info.close();
Intent fullModuleDetails = new Intent();
fullModuleDetails.setClassName("com.example.collegetimetable",
"com.example.collegetimetable.ModuleDetails");
fullModuleDetails.putExtra("list1", module_info);
startActivity(fullModuleDetails);
}
Here is the getAllData method which retrieves all the information from the database. How could I alter this method, to retrieve only the information for the row relating to the particular listView item that was clicked by the user?
public String getAllData() {
String[] columns = new String[]{ KEY_ROWID, KEY_MODULE_CODE, KEY_MODULE_NAME, KEY_LECTURE_PRACTICAL, KEY_LECTURE_DAY, KEY_START_TIME,KEY_END_TIME, KEY_LOCATION, ADDITIONAL_INFO};
Cursor c = ourDatabase.query(DATABASE_MODULES, columns, null, null, null, null, null);
String results = "";
int indexRow = c.getColumnIndex(KEY_ROWID);
int indexModCode = c.getColumnIndex(KEY_MODULE_CODE);
int indexModName = c.getColumnIndex(KEY_MODULE_NAME);
int indexLectPrac = c.getColumnIndex(KEY_LECTURE_PRACTICAL);
int indexLectDay = c.getColumnIndex(KEY_LECTURE_DAY);
int indexLectStart = c.getColumnIndex(KEY_START_TIME);
int indexLectEnd = c.getColumnIndex(KEY_END_TIME);
int indexLectLoc = c.getColumnIndex(KEY_LOCATION);
int indexLectInfo = c.getColumnIndex(ADDITIONAL_INFO);
for (c.moveToFirst();!c.isAfterLast();c.moveToNext()){
results = results + ( c.getString(indexModCode) + " " + c.getString(indexModName) + " " + c.getString(indexLectPrac)
+ " " + c.getString(indexLectDay) + " " + c.getString(indexLectStart) + " " + c.getString(indexLectEnd) + " "
+ c.getString(indexLectLoc) + " " + c.getString(indexLectInfo));
}
return results;
}
Thanks for any help
Instead of looping through the data, you would do something along the lines:
public String getAllDataForRow(int row) {
String[] columns = new String[]{ KEY_ROWID, KEY_MODULE_CODE, KEY_MODULE_NAME, KEY_LECTURE_PRACTICAL, KEY_LECTURE_DAY, KEY_START_TIME,KEY_END_TIME, KEY_LOCATION, ADDITIONAL_INFO};
Cursor c = ourDatabase.query(DATABASE_MODULES, columns, null, null, null, null, null);
if(c.moveToPosition(row)) {
String result = "";
for(int columnIndex = 0; columnIndex<c.getColumnCount();columnIndex++) {
result += c.getString(columnIndex)+" ";
}
return result;
} else {
throw new IllegalArgumentException("Row " + row + " does not exist");
}
}
Also, if you didn't know: If you want all columns, you actually do not have to specify them in the projection, but can just pass null instead of columns.
Hope that helps.
I'm messing around with some SQLite databases for an Android app. I have a 'player' table with several players, and a one-to-many 'skill' table which has each player's skill points, like Shooting and Rebounding.
I have one activity in the app for actually filling out textboxes and inserting a player into the database. When the user hits the 'Add Player' button, a row is inserted into the 'player' table and a row is inserted into the 'skills' table which has a foreign key that references the 'player' table. After these inserts, I did a query to check if I could read the 'Shooting' value from the 'skills' table and put it in a Toast notification. That worked fine, and the code I used is here:
SQLiteDatabase db2 = dbHelper.getReadableDatabase();
String[] projection = { "shooting" };
String sortOrder = "shooting" + " DESC";
Cursor c = db2.query(
"skills", // The table to query
projection, // The columns to return
null, // The columns for the WHERE clause
null, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
sortOrder // The sort order
);
c.moveToFirst();
int shooting = c.getInt(c.getColumnIndexOrThrow("shooting"));
Toast.makeText(this, "" + shooting, Toast.LENGTH_SHORT).show();
After I saw that this was working, I commented it out and put in an Intent to make the app switch to the 'Roster' activity after the player and skills are inserted. On the 'Roster' activity, I want to get each player's 'Shooting' skill. When I use the exact same code from above (which works from the other activity) I get an error which says:
06-16 15:59:42.602: E/AndroidRuntime(31537): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.silverray.messaround/com.silverray.messaround.Roster}: java.lang.IllegalArgumentException: column 'shooting' does not exist
I can't figure out why it's saying the 'shooting' column doesn't exist when I know I included it in my SQL Create statement, and I was even able to read this exact same column with the same code from another activity.
Thanks for reading. Any ideas?
EDIT: This is the full code for the Roster activity:
public class Roster extends Activity {
int teamID = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_roster);
// CHECK ROSTER
DatabaseContract dbContract = new DatabaseContract();
DatabaseContract.DbHelper dbHelper = dbContract.new DbHelper(this);
SQLiteDatabase dbCheck = dbHelper.getReadableDatabase();
Intent intent = getIntent();
int ID = intent.getIntExtra("ID", 1);
teamID = ID;
String stringID = String.valueOf(ID);
String[] projection = { "_id, playerFirstName, playerLastName, playerPosition" };
String sortOrder = "playerFirstName" + " ASC";
Cursor c = dbCheck.query(
"player",
projection,
null,
null,
null,
null,
sortOrder
);
c.moveToFirst();
int rowsAffected = c.getCount();
if (rowsAffected < 1) {
TextView rosterList = (TextView) findViewById(R.id.txtListRoster);
rosterList.setText("Your team doesn't have any players!");
c.close();
dbCheck.close();
} else {
String players = "";
for (int l = 0; l < rowsAffected; l++) {
String playerName = c.getString(c.getColumnIndexOrThrow("playerFirstName"));
String playerLastName = c.getString(c.getColumnIndexOrThrow("playerLastName"));
String position = c.getString(c.getColumnIndexOrThrow("playerPosition"));
int playerID = c.getInt(c.getColumnIndexOrThrow("_id"));
String player_ID = String.valueOf(playerID);
String pos = "";
if (position.equals("Point Guard")) {
pos = "PG";
} else if (position.equals("Shooting Guard")) {
pos = "SG";
} else if (position.equals("Small Forward")) {
pos = "SF";
} else if (position.equals("Power Forward")) {
pos = "PF";
} else if (position.equals("Center")) {
pos = "C";
}
SQLiteDatabase db2 = dbHelper.getReadableDatabase();
String[] projection2 = { "shooting" };
String sortOrder2 = "shooting" + " DESC";
Cursor c2 = db2.query(
"skills",
projection2,
null,
null,
null,
null,
sortOrder2
);
c2.moveToFirst();
//** Everything works until this line:
int shooting = c2.getInt(c.getColumnIndexOrThrow("shooting"));
players += playerName + " " + playerLastName + " (" + pos + ") Shooting: ";
if (l != (rowsAffected - 1)) {
players += "\n";
}
TextView rosterList = (TextView) findViewById(R.id.txtListRoster);
rosterList.setText(players);
if (l != (rowsAffected - 1)) {
c.moveToNext();
}
c2.close();
}
c.close();
dbCheck.close();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.roster, menu);
return true;
}
public void addPlayer(View view) {
Intent goToAddPlayer = new Intent(this, AddPlayer.class);
goToAddPlayer.putExtra("ID", teamID);
this.startActivity(goToAddPlayer);
this.finish();
return;
}
}
int shooting = c2.getInt(c.getColumnIndexOrThrow("shooting"));
should be
int shooting = c2.getInt(c2.getColumnIndexOrThrow("shooting"));
You are now working on 2nd query but trying to get column index from 1st.
sqlite query for store all the data in single array.means I have a table where 8 fields are there and I want to retrive all the data in a single array and return array.
Can I do this?
Code from the comment below:
public String[] login1(String email) throws SQLException {
/* Cursor mCursor = db.rawQuery("SELECT * FROM " + TABLE_NAME
+ " WHERE email=? AND password=?",
new String[]{username,res});
*/
try {
/*Cursor c = db.rawQuery("select * from member where email ="
+ "\""+ email.trim() + "\""+" and password="
+ "\""+ res.trim() + "\"", null);
*/
Cursor c = db.rawQuery("Select usermasterid,invalidlogincount,password,"
+ "nextpage,status,user,businessnextpage "
+ "from member where email " + "\""+ email.trim()
+ "\"", null);
There is not enough info in your question, but it should be roughly like this(assuming your data is int):
public int[] getDBRowAsArray() {
int[] myArray = new int[8];
Cursor cursor = yourSQLiteOpenHelper.rawQuery("Your SQL query here", null);
for(int i = 0; i < 8; i++) {
myArray[i] = cursor.getInt(i);
}
return myArray;
}
I assume there are 8 records and not fields in the db.
public String[] getData(){
Cursor c = db.query(args...);
if(c != null && c.moveToFirst()){
int count = c.getCount();
String[] vals = new String[count];
for(int i = 0; i < count; i++){
vals[i] = c.getString(c.getColumnIndex(Table.COLUMN));
c.moveToNext();
}
c.close();
return vals;
}
return null;
}