Reputation: 131
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
Upvotes: 0
Views: 602
Reputation: 5349
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
Upvotes: 1