所以这是我的应用程序的一般流程:
Main Menu
- > Account Manager
- > Account Details
- > Payment Schedule
Account Manager
中用户选择的数据通过Account Details
传递给Serialized Object
。然后从Account Details
开始,Serialized Object
将Payment Schedule
传递给PayTable
进行计算,所有结果都会专门投入我的数据库{.1}}。
每个帐户都可以有多笔付款,以确保我可以将正确的付款条目与我GroupID
中PayTable
的正确帐户相关联。因此,现在PayTable
中的条目被分配了GroupID
,该AccountID
基于传递给AccountsTable
的{{1}}中的Payment Schedule
。
所以,如果AccountID = 1
然后GroupID = 1
。
使用此功能,我可以过滤掉正确帐户的正确付款,然后在GridView
Payments Schedule
中显示。
编辑(删除了大部分不再重要的旧帖子,但将我的情况的要点放在首位以供参考)
摘要
我有两张表Account
和Payment
。 Account
colID
Payment
GroupID
GroupID
colID
。 colID
取决于所选帐户的GroupID
。因此,如果GroupID
说3,那么该实例中的所有付款条目也将被分配{3}的colID
,因此我可以将正确的付款与正确的帐户配对。
问题是我需要比较两个字段(db.execSQL("CREATE VIEW " + viewPayments +
" AS SELECT " + payTable + "." + colPayID + " AS _id," +
" " + accountsTable + "." + colID + "," +
" " + payTable + "." + colGroupID + "," +
" " + payTable + "." + colPayBal + "," +
" " + payTable + "." + colInterest + "," +
" " + payTable + "." + colPayDue + "," +
" " + payTable + "." + colDateDue + "," +
" " + payTable + "." + colPaid + "" +
" FROM " + payTable +
" JOIN " + accountsTable + " ON " + payTable + "." + colGroupID + " = " + accountsTable + "." + colID );
== Cursor filterpay(String Payment) {
SQLiteDatabase db = this.getWritableDatabase();
String[] columns = new String[]{"_id", colGroupID, colPayBal, colInterest, colPayDue, colDateDue, colPaid};
Cursor c = db.query(viewPayments, columns, colGroupID + "=?", new String[]{Payment}, null, null, null);
return c;
)并获取与条件匹配的所有条目。所以这意味着两个表中两个字段的交叉比较。
解决方案
使用INNER JOIN并创建了一个更简单的GridView引用视图:
TextView txt;
txt = (TextView)findViewById(R.id.putithere);
txt.setVisibility(View.GONE);
public void Paygrid(){
dbHelper = new DatabaseHelper(this);
String Payment = String.valueOf(txt.getText());
Cursor a = dbHelper.filterpay(Payment);
startManagingCursor(a);
String[] from = new String[]{DatabaseHelper.colPayBal, DatabaseHelper.colInterest, DatabaseHelper.colPayDue, DatabaseHelper.colDateDue, DatabaseHelper.colPaid};
int[] to = new int[]{R.id.Amount,R.id.Interest, R.id.Total, R.id.DateDue, R.id.Paid};
SimpleCursorAdapter saa = new SimpleCursorAdapter(this, R.layout.paygrid, a, from, to);
intgrid.setAdapter(saa);
修正了我的查询
txt
最后但并非最不重要的是,调整我的代码以便在我的GridView上发布。
colID
}
{{1}}这些东西只是我懒得找到一个更清晰的方法来获取帐户的{{1}}并在我的'PayGrid'中引用它所以我可能不会建议我看待。
此外,因为我是新来的,所以当我回答我自己的问题时,我不知道如何将这个问题标记为已回答,所以如果有人能够指出那就好了。除此之外,我希望这可以帮助将来的某个人。欢呼声。
另一方面,感谢随意的人!非常感谢您的帮助。
答案 0 :(得分:0)
我刚看到"回答你的问题"页面底部的按钮在编辑后发布我自己的解决方案....是的,当我这样做时,我做了facepalm。
<强>解决方案强>
使用INNER JOIN并创建了一个更简单的GridView引用视图:
db.execSQL("CREATE VIEW " + viewPayments +
" AS SELECT " + payTable + "." + colPayID + " AS _id," +
" " + accountsTable + "." + colID + "," +
" " + payTable + "." + colGroupID + "," +
" " + payTable + "." + colPayBal + "," +
" " + payTable + "." + colInterest + "," +
" " + payTable + "." + colPayDue + "," +
" " + payTable + "." + colDateDue + "," +
" " + payTable + "." + colPaid + "" +
" FROM " + payTable +
" JOIN " + accountsTable + " ON " + payTable + "." + colGroupID + " = " + accountsTable + "." + colID );
修正了我的查询
Cursor filterpay(String Payment) {
SQLiteDatabase db = this.getWritableDatabase();
String[] columns = new String[]{"_id", colGroupID, colPayBal, colInterest, colPayDue, colDateDue, colPaid};
Cursor c = db.query(viewPayments, columns, colGroupID + "=?", new String[]{Payment}, null, null, null);
return c;
最后但并非最不重要的是,调整我的代码以便在我的GridView上发布。
TextView txt;
txt = (TextView)findViewById(R.id.putithere);
txt.setVisibility(View.GONE);
public void Paygrid(){
dbHelper = new DatabaseHelper(this);
String Payment = String.valueOf(txt.getText());
Cursor a = dbHelper.filterpay(Payment);
startManagingCursor(a);
String[] from = new String[]{DatabaseHelper.colPayBal, DatabaseHelper.colInterest, DatabaseHelper.colPayDue, DatabaseHelper.colDateDue, DatabaseHelper.colPaid};
int[] to = new int[]{R.id.Amount,R.id.Interest, R.id.Total, R.id.DateDue, R.id.Paid};
SimpleCursorAdapter saa = new SimpleCursorAdapter(this, R.layout.paygrid, a, from, to);
intgrid.setAdapter(saa);
}
txt
这些东西只是我懒得找到一个更清晰的方式来获取帐户的colID
并在PayGrid
中引用它,所以我可能不会推荐在这方面跟着我。