在微调器设置文本 [英] Set text on Spinner

查看:194
本文介绍了在微调器设置文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是AccountListView,它检索,我已在数据库中添加列表视图显示数据,我已经添加了现金和银行账户,当我在名单上的现金点击查看打开交易意向,其中有在其现金和银行已经增加了一个微调,我希望它显示我已经点击列表视图中的数据。请注意,对于现金和银行显示器成功地只为微调的平衡。

 公共类AccountListActivity扩展活动实现OnClickListener,OnItemClickListener {私人的ListView AccountListView;
私人按钮addNewAccountButton;私人ListAdapter AccountListAdapter;
私人的ArrayList< AccountDetails> pojoArrayList;/ **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.list);    AccountListView =(ListView控件)findViewById(R.id.AccountListView);
    AccountListView.setOnItemClickListener(本);
    registerForContextMenu(AccountListView);
    addNewAccountButton =(按钮)findViewById(R.id.namesListViewAddButton);
    addNewAccountButton.setOnClickListener(本);    pojoArrayList =新的ArrayList< AccountDetails>();
    AccountListAdapter =新ArrayAdapter<串GT;(这一点,android.R.layout.simple_list_item_1,populateList());    AccountListView.setAdapter(AccountListAdapter);}
@覆盖
公共无效onCreateContextMenu(文本菜单菜单视图V,ContextMenuInfo menuInfo){
super.onCreateContextMenu(菜单,V,menuInfo);
    menu.setHeaderTitle(菜单);
    menu.add(0,v.getId(),0,更新);
    menu.add(0,v.getId(),0,删除);
    menu.add(0,v.getId(),0,取消);}公开名单<串GT; populateList(){
    清单<串GT;为accountList =新的ArrayList<串GT;();
    DatabaseAdapter openHelperClass =新DatabaseAdapter(本);
    SQLiteDatabase sqliteDatabase = openHelperClass.getReadableDatabase();
    光标光标= sqliteDatabase.query(DatabaseAdapter.TABLE_ACCOUNT,NULL,NULL,NULL,NULL,NULL,NULL);
    startManagingCursor(光标);
    而(cursor.moveToNext()){
        串aBNAME = cursor.getString(cursor.getColumnIndex(DatabaseAdapter.KEY_BANKNAME));
        串aBTYPE = cursor.getString(cursor.getColumnIndex(DatabaseAdapter.KEY_TYPE));
        串aAccNum = cursor.getString(cursor.getColumnIndex(DatabaseAdapter.KEY_ACCNUM));
        字符串阿巴尔= cursor.getString(cursor.getColumnIndex(DatabaseAdapter.KEY_BALANCE));
        串aEDate = cursor.getString(cursor.getColumnIndex(DatabaseAdapter.KEY_EXPIRYDATE));
        AccountDetails ugPojoClass =新AccountDetails();
        ugPojoClass.setaBankName(aBNAME);
        ugPojoClass.setaAccountType(aBTYPE);
        ugPojoClass.setaAccountNumber(aAccNum);
        ugPojoClass.setaBalance(ABAL);
        ugPojoClass.setaDate(aEDate);        pojoArrayList.add(ugPojoClass);        AccountList.add(aBNAME);
    }    sqliteDatabase.close();    返回为accountList;
}    @覆盖
公共无效onItemClick(适配器视图<>为arg0,ARG1观,诠释ARG2,长ARG3){    Toast.makeText(getApplicationContext(),点击了:+ ARG2,Toast.LENGTH_SHORT).show();    意图updateDeleteAccountIntent =新意图(这一点,Transaction.class);    AccountDetails clickedObject = pojoArrayList.get(ARG2);    捆绑dataBundle =新包();
    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);}

在该交易的目的是打开它需要的价值
Transaction.java

 公共类交易活动扩展实现OnClickListener { 私人微调类别,账户,typerp;
 私人TextView的tvSaveNew,tvDisplayDate;
 私人的EditText ITEMNAME,金额,票据;
 私人的EditText平衡,结果;
 私人的ImageButton TransDate,ImageButton1;
 私人按钮来保存,蝾螈;私人字符串bundledBankName;
私人字符串bundledBankType;
私人字符串bundledBankNumber;
私人字符串bundledBankBalance;
私人字符串bundledBankDate;
私人字符串BankNameValue;
私人字符串NewBankBalanceValue;
私人字符串BankTypeValue;
私人字符串BankNumberValue;
私人字符串BankBalanceValue;
私人字符串BankDateValue; 私人诠释年;
 私人诠释月;
 私人诠释天;
 静态最终诠释DATE_DIALOG_ID = 999; 私人的ArrayList< TransactionDetails> TransactionDetailsObjArrayList;
/ **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.transaction);    节省=(按钮)findViewById(R.id.TbtnSave);
    蝾螈=(按钮)findViewById(R.id.btnNewTran);
    TransDate =(的ImageButton)findViewById(R.id.transDate);
    分类=(微调)findViewById(R.id.Tcategory);
    账户=(微调)findViewById(R.id.TAccount);
    typerp =(微调)findViewById(R.id.TypeR);
    ITEMNAME =(EditText上)findViewById(R.id.TransItemName);
    金额=(EditText上)findViewById(R.id.TransAmount);
    注=(EditText上)findViewById(R.id.tranNote);
    余额=(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< TransactionDetails>();
    loadSpinnerData();    捆绑takeBundledData = getIntent()getExtras()。
    bundledBankName = takeBundledData.getString(clickedBankName);    bundledBankBalance = takeBundledData.getString(clickedBankBalance);    Account.setSelection(0);
    Balance.setText(bundledBankBalance);}


解决方案

测试了这只是前一阵子与包含字符串列表的微调,似乎很好地工作。可以帮助别人。

 公共无效setSpinText(旋转器的旋转,字符串文本)
{
    的for(int i = 0; I< spin.getAdapter()getCount将();我++)
    {
        如果(spin.getAdapter()的getItem(I)的ToString()。包含(文本))
        {
            spin.setSelection(ⅰ);
        }
    }}

:)

This is the AccountListView, it retrieve and displays data that i have been added in database in a list view, i have added cash and bank account, when i clicked on cash in the list view it open the transaction intent, which has a spinner on which cash and bank has been added, i want it to display the data that i have clicked on the list view. Note that for the balance of cash and bank display succesfully only for the spinner.

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);

}

When the transaction intent is open it take value of the 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);

}

解决方案

Tested this just a while ago with a spinner that contains a list of strings, seems to work fine. Might help someone.

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);
        }
    }

}

:)

这篇关于在微调器设置文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆