Android 在微调器上设置文本
这是AccountListView,它检索并显示我在列表视图中添加到数据库中的数据,我添加了现金和银行帐户,当我在列表视图中单击现金时,它打开事务意图,它有一个微调器,其中添加了现金和银行,我希望它显示我在列表视图中单击的数据。请注意,对于现金余额和银行余额,仅对微调器成功显示Android 在微调器上设置文本,android,android-spinner,Android,Android Spinner,这是AccountListView,它检索并显示我在列表视图中添加到数据库中的数据,我添加了现金和银行帐户,当我在列表视图中单击现金时,它打开事务意图,它有一个微调器,其中添加了现金和银行,我希望它显示我在列表视图中单击的数据。请注意,对于现金余额和银行余额,仅对微调器成功显示 public class AccountListActivity extends Activity implements OnClickListener, OnItemClickListener { private L
public class AccountListActivity extends Activity implements OnClickListener, OnItemClickListener {
private ListView AccountListView;
private Button addNewAccountButton;
private ListAdapter AccountListAdapter;
private ArrayList<AccountDetails> pojoArrayList;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
AccountListView = (ListView) findViewById(R.id.AccountListView);
AccountListView.setOnItemClickListener(this);
registerForContextMenu(AccountListView);
addNewAccountButton = (Button) findViewById(R.id.namesListViewAddButton);
addNewAccountButton.setOnClickListener(this);
pojoArrayList = new ArrayList<AccountDetails>();
AccountListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, populateList());
AccountListView.setAdapter(AccountListAdapter);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Menu");
menu.add(0, v.getId(), 0, "Update");
menu.add(0, v.getId(), 0, "Delete");
menu.add(0, v.getId(), 0, "Cancel");
}
public List<String> populateList(){
List<String> AccountList = new ArrayList<String>();
DatabaseAdapter openHelperClass = new DatabaseAdapter(this);
SQLiteDatabase sqliteDatabase = openHelperClass.getReadableDatabase();
Cursor cursor = sqliteDatabase.query(DatabaseAdapter.TABLE_ACCOUNT, null, null, null, null, null, null);
startManagingCursor(cursor);
while (cursor.moveToNext()) {
String aBNAME = cursor.getString(cursor.getColumnIndex(DatabaseAdapter.KEY_BANKNAME));
String aBTYPE = cursor.getString(cursor.getColumnIndex(DatabaseAdapter.KEY_TYPE));
String aAccNum = cursor.getString(cursor.getColumnIndex(DatabaseAdapter.KEY_ACCNUM));
String aBal = cursor.getString(cursor.getColumnIndex(DatabaseAdapter.KEY_BALANCE));
String aEDate = cursor.getString(cursor.getColumnIndex(DatabaseAdapter.KEY_EXPIRYDATE));
AccountDetails ugPojoClass = new AccountDetails();
ugPojoClass.setaBankName(aBNAME);
ugPojoClass.setaAccountType(aBTYPE);
ugPojoClass.setaAccountNumber(aAccNum);
ugPojoClass.setaBalance(aBal);
ugPojoClass.setaDate(aEDate);
pojoArrayList.add(ugPojoClass);
AccountList.add(aBNAME);
}
sqliteDatabase.close();
return AccountList;
}
@Override
public void onItemClick( AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Toast.makeText(getApplicationContext(), "Clicked on :" + arg2, Toast.LENGTH_SHORT).show();
Intent updateDeleteAccountIntent = new Intent(this, Transaction.class);
AccountDetails clickedObject = pojoArrayList.get(arg2);
Bundle dataBundle = new Bundle();
dataBundle.putString("clickedBankName", clickedObject.getaBankName());
dataBundle.putString("clickedBankType", clickedObject.getaAccountType());
dataBundle.putString("clickedBankNumber", clickedObject.getaAccountNumber());
dataBundle.putString("clickedBankBalance", clickedObject.getaBalance());
dataBundle.putString("clickedExpiryDate", clickedObject.getaDate());
updateDeleteAccountIntent.putExtras(dataBundle);
startActivity(updateDeleteAccountIntent);
}
公共类AccountListActivity扩展活动实现OnClickListener、OnItemClickListener{
私有ListView帐户ListView;
私有按钮addNewAccountButton;
私有ListAdapter帐户ListAdapter;
私人ArrayList pojoArrayList;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
AccountListView=(ListView)findViewById(R.id.AccountListView);
AccountListView.setOnItemClickListener(此);
registerForContextMenu(AccountListView);
addNewAccountButton=(按钮)findViewById(R.id.NameListViewAddButton);
addNewAccountButton.setOnClickListener(此);
pojoArrayList=新的ArrayList();
AccountListAdapter=new ArrayAdapter(这个,android.R.layout.simple_list_item_1,populateList());
setAdapter(AccountListAdapter);
}
@凌驾
public void onCreateContextMenu(ContextMenu菜单,视图v,ContextMenuInfo菜单信息){
super.onCreateContextMenu(menu,v,menuInfo);
菜单。设置标题(“菜单”);
添加(0,v.getId(),0,“更新”);
添加(0,v.getId(),0,“删除”);
添加(0,v.getId(),0,“取消”);
}
公共列表populateList(){
List AccountList=new ArrayList();
DatabaseAdapter openHelperClass=新的DatabaseAdapter(此);
SQLiteDatabase SQLiteDatabase=openHelperClass.getReadableDatabase();
Cursor Cursor=sqliteDatabase.query(DatabaseAdapter.TABLE_ACCOUNT,null,null,null,null);
开始管理游标(游标);
while(cursor.moveToNext()){
String aBNAME=cursor.getString(cursor.getColumnIndex(DatabaseAdapter.KEY_BANKNAME));
String aBTYPE=cursor.getString(cursor.getColumnIndex(DatabaseAdapter.KEY_TYPE));
String aAccNum=cursor.getString(cursor.getColumnIndex(DatabaseAdapter.KEY_ACCNUM));
String aBal=cursor.getString(cursor.getColumnIndex(DatabaseAdapter.KEY_BALANCE));
String aEDate=cursor.getString(cursor.getColumnIndex(DatabaseAdapter.KEY_EXPIRYDATE));
AccountDetails ugPojoClass=新AccountDetails();
ugPojoClass.setaBankName(aBNAME);
ugPojoClass.SETAAACCOUNTTYPE(aBTYPE);
ugPojoClass.SetAAAccountNumber(aAccNum);
ugPojoClass.setaBalance(aBal);
刚毛乌贼(伊蚊);
添加(ugPojoClass);
AccountList.add(aBNAME);
}
sqliteDatabase.close();
返回帐户列表;
}
@凌驾
公共视图单击(AdapterView arg0、视图arg1、整型arg2、长型arg3){
Toast.makeText(getApplicationContext(),“单击:”+arg2,Toast.LENGTH\u SHORT.show();
Intent updateDeleteAccountIntent=新的Intent(这个,Transaction.class);
AccountDetails clickedObject=pojoArrayList.get(arg2);
Bundle-dataBundle=新Bundle();
putString(“clickedBankName”,clickedObject.getaBankName());
putString(“clickedBankType”,clickedObject.getAAAccountType());
putString(“clickedBankNumber”,clickedObject.getAAAccountNumber());
putString(“clickedBankBalance”,clickedObject.GetAbance());
putString(“clickedExpiryDate”,clickedObject.getaDate());
updateDeleteAccountIntent.putExtras(数据绑定);
startActivity(updateDeleteAccountIntent);
}
当事务意图打开时,它将获取
Transaction.java
public class Transaction extends Activity implements OnClickListener{
private Spinner Category, Account, typerp;
private TextView tvSaveNew, tvDisplayDate;
private EditText ItemName, Amount, Notes;
private EditText Balance, Result;
private ImageButton TransDate, ImageButton1;
private Button save, newt;
private String bundledBankName;
private String bundledBankType;
private String bundledBankNumber;
private String bundledBankBalance;
private String bundledBankDate;
private String BankNameValue;
private String NewBankBalanceValue;
private String BankTypeValue;
private String BankNumberValue;
private String BankBalanceValue;
private String BankDateValue;
private int year;
private int month;
private int day;
static final int DATE_DIALOG_ID = 999;
private ArrayList<TransactionDetails> TransactionDetailsObjArrayList;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.transaction);
save = (Button) findViewById(R.id.TbtnSave);
newt = (Button) findViewById(R.id.btnNewTran);
TransDate = (ImageButton) findViewById(R.id.transDate);
Category = (Spinner) findViewById(R.id.Tcategory);
Account = (Spinner) findViewById(R.id.TAccount);
typerp = (Spinner) findViewById(R.id.TypeR);
ItemName = (EditText) findViewById(R.id.TransItemName);
Amount = (EditText) findViewById(R.id.TransAmount);
Notes = (EditText) findViewById(R.id.tranNote);
Balance = (EditText) findViewById(R.id.RetrieveBalance);
Result = (EditText) findViewById(R.id.ResultBalance);
tvDisplayDate = (TextView) findViewById(R.id.ttvDisplayDate);
save.setOnClickListener(this);
newt.setOnClickListener(this);
setCurrentDateOnView();
TransDate.setOnClickListener(this);
TransactionDetailsObjArrayList = new ArrayList<TransactionDetails>();
loadSpinnerData();
Bundle takeBundledData = getIntent().getExtras();
bundledBankName = takeBundledData.getString("clickedBankName");
bundledBankBalance = takeBundledData.getString("clickedBankBalance");
Account.setSelection(0);
Balance.setText(bundledBankBalance);
}
公共类事务扩展活动实现OnClickListener{
私人微调器类别、帐户、类型RP;
私有文本视图tvSaveNew、TVSPLAYDATE;
私人编辑文本项目名称、金额、备注;
私人编辑文本平衡,结果;
私有ImageButton转换日期,ImageButton1;
私有按钮保存,newt;
私有字符串bundledBankName;
私有字符串bundledBankType;
私有字符串bundledBankNumber;
私人字符串绑定银行余额;
私有字符串bundledBankDate;
私有字符串bankname值;
私有字符串NewBankBalanceValue;
私有字符串BankTypeValue;
私有字符串BankNumberValue;
私有字符串BankBalanceValue;
私有字符串BankDateValue;
私人国际年;
私人整数月;
私人国际日;
静态最终整数日期对话框ID=999;
私有ArrayList TransactionDetailsObjArrayList;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.transaction);
保存=(按钮)findViewById(R.id.TbtnSave);
newt=(按钮)findViewById(R.id.btnNewTran);
TransDate=(ImageButton)findViewById(R.id.TransDate);
类别=(微调器)findViewById(R.id.Tcategory);
Account=(微调器)findViewById(R.id.TAccount);
typerp=(微调器)findViewById(R.id.TypeR);
ItemName=(EditText)findViewById(R.id.TransItemName);
金额=(EditText)findViewById(R.id.TransAmount);
Notes=(EditText)findViewById(R.id.tranNote);
Balance=(EditText)findViewById(R.id.RetrieveBalance);
结果=(EditText)findViewById(R.id.ResultBalance);
tvDisplayDate=(TextView)findViewById(R.id.ttvDisplayDate);
save.setOnClickListener(这个);
newt.setOnClickListener(此);
setCurrentDateOnView();
TransDate.setOnClickListener(这个);
TransactionDetailsObjArrayList=新建ArrayList();
加载SpinnerData();
Bundle takebundledata=getIntent().getExtras();
bundledBankName=takeBundledData.getString(“clickedBankName”);
bundledBankBalance=takeBundledData.getString(“clickedBankBalance”);
Account.setSelecti
ArrayAdapter<String> adapter = new ArrayAdapter<String>(PaymentTerms_NewInvoice_Activity.this, android.R.layout.simple_spinner_item, mTempArray);
mSpnTermsCode.setAdapter(adapter);
mSpnTermsCode.setSelection(0);
Spinner Account;
ArrayAdapter<String> productaddapter;
List<String> productname=new ArrayList<String>();
//Fill your data in productname arraylist..
productaddapter = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_spinner_dropdown_item, productname);
Account.setAdapter(productaddapter);
public void setSpinText(Spinner spin, String text)
{
for(int i= 0; i < spin.getAdapter().getCount(); i++)
{
if(spin.getAdapter().getItem(i).toString().contains(text))
{
spin.setSelection(i);
}
}
}
fun Spinner.setSpinnerText(text: String) {
for (i in 0 until this.adapter.count) {
if (this.adapter.getItem(i).toString().contains(text)) {
this.setSelection(i)
}
}
}