【发布时间】:2016-04-13 18:19:22
【问题描述】:
用户界面
User interface
和数据库
Sqlite Database
在我的代码中,我想比较选定的单选按钮是否等于数据库中的帐户类型。
如果它们相等,则必须按照 if 语句中的说明开始活动。
我对我的帐户类型进行了硬编码,它可以工作,但现在我想从数据库中获取帐户类型并将其与所选单选按钮的字符串进行比较
//Button To submit selected Radio button for a specicific account
public void onClickSubmitAccount(){
radio_accounts = (RadioGroup) findViewById(R.id.radioAccounts);
btnSubmitAccount = (Button) findViewById(R.id.btnSubmitAccount);
btnSubmitAccount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int selected_account = radio_accounts.getCheckedRadioButtonId();
radio_button_accounts = (RadioButton) findViewById(selected_account);
Toast.makeText(UserHomePageActivity.this, radio_button_accounts.getText().toString(), Toast.LENGTH_SHORT).show();
if ((radio_button_accounts.getText().toString()).equals("Savings Account")) {
Intent accountIntent = new Intent(UserHomePageActivity.this, SavingsTransactionsActivity.class);
startActivity(accountIntent);
}
else if ((radio_button_accounts.getText().toString()).equals("Credit Account")) {
Intent accountIntent = new Intent(UserHomePageActivity.this, CreditTransactionActivity.class);
startActivity(accountIntent);
}
else if ((radio_button_accounts.getText().toString()).equals("Cheque Account")) {
Intent accountIntent = new Intent(UserHomePageActivity.this, ChequeTransactionActivity.class);
startActivity(accountIntent);
}
else {
Toast.makeText(UserHomePageActivity.this, "Sorry, No accout has been selected", Toast.LENGTH_LONG).show();
}
}
});
}
//从表账户的数据库中获取数据 公共 ArrayList getAllAccount() {
ArrayList<AccountClass> accountList = new ArrayList<AccountClass>();
Cursor cursor = bankingAppDB.query(Constants.tblAccount, null,null,null,null,null,null);
AccountClass account;
if(cursor.moveToFirst()){
while (cursor.moveToNext())
{
String acc_number = cursor.getString(cursor.getColumnIndex(Constants.ACCOUNT_NUMBER));
String account_type = cursor.getString(cursor.getColumnIndex(Constants.ACCOUNT_TYPE));
double balance = Double.parseDouble(cursor.getString(cursor.getColumnIndex(Constants.ACCOUNT_BALANCE)));
Log.d(" Info"," Account Number: " +acc_number+" type: "+account_type);
account = new AccountClass(acc_number);
accountList.add(account);
}
}
return accountList;
}
//在账户表中添加账号、账户类型和余额 public void addAccount(AccountClass 帐户){
ContentValues values = new ContentValues();
values.put(Constants.ACCOUNT_NUMBER, account.getAccountNumber());
values.put(Constants.ACCOUNT_BALANCE, account.getAccountBalance());
values.put(Constants.ACCOUNT_TYPE, account.getAccountType());
bankingAppDB.insert(Constants.tblAccount, null, values);
bankingAppDB.close();
}
【问题讨论】:
-
您的数据库处理程序在哪里?
-
我正在尝试复制数据库处理程序的代码,它太长了,请帮助我如何上传课程@Ricardo Barroca
-
你没有getAccount或getAccountType的方法吗?
-
我重新编辑了我的代码,希望现在有意义