Android 微调器项目对单击没有影响!!!,列表只会保留在屏幕上

Android 微调器项目对单击没有影响!!!,列表只会保留在屏幕上,android,android-spinner,onitemclicklistener,Android,Android Spinner,Onitemclicklistener,我有一个活动,它接受用户提供的银行名称和帐号。银行名称和相应的帐号存储在数据库中。现在在另一个活动中有两个微调器,其中一个获取银行名称并用它们填充自己,另一个获取对应于该银行的账号。我成功地填充了微调器。我唯一的问题是,第一个微调器中的条目(包含银行名称)不可单击,因此第二个微调器也变得无用。我无法理解其原因。以下是微调器的代码: // in onCreate() function // for the spinner holding bank name Cursor cur

我有一个活动,它接受用户提供的银行名称和帐号。银行名称和相应的帐号存储在数据库中。现在在另一个活动中有两个微调器,其中一个获取银行名称并用它们填充自己,另一个获取对应于该银行的账号。我成功地填充了微调器。我唯一的问题是,第一个微调器中的条目(包含银行名称)不可单击,因此第二个微调器也变得无用。我无法理解其原因。以下是微调器的代码:

   // in onCreate() function
   // for the spinner holding bank name
    Cursor cursor = myDatabase.getData();
    cursor.moveToFirst();
    myAdapter = new SimpleCursorAdapter(AddTransaction.this,
                R.layout.spinnerlayout, cursor,
                new String[] { DatabaseClass.KEY_BANK_NAME_ID },
                new int[] { R.id.bankName },
                SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    mySpinner.setAdapter(myAdapter);

    get_datafrom_spinner = cursor.getString(cursor
                .getColumnIndex(DatabaseClass.KEY_BANK_NAME_ID));
        // Toast.makeText(AddTransaction.this, get_datafrom_spinner,
        // Toast.LENGTH_LONG).show();

        // mySpinner.setOnItemSelectedListener(this);

    myDatabase.close();



@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position,
        long arg3) {
    // TODO Auto-generated method stub
    try {
        myDatabase.open();

        int pos = position;
        Cursor cursor = (Cursor) myAdapter.getItem(pos);
        bank_name = cursor.getString(cursor // name of the bank
                                            // selected
                .getColumnIndex(DatabaseClass.KEY_BANK_NAME_ID));
        myAdapter = new SimpleCursorAdapter(AddTransaction.this,
                R.layout.spinnerlayout, cursor,
                new String[] { DatabaseClass.KEY_BANK_NAME_ID, },
                new int[] { R.id.bankName },
                SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        mySpinner.setAdapter(myAdapter);

        // Toast.makeText(AddTransaction.this, s,
        // Toast.LENGTH_SHORT).show();

        // returns the account numbers corresponding to this bank name
        Cursor c = myDatabase.getAccountData(bank_name);
        c.moveToFirst();

        myAdapter_for_account = new SimpleCursorAdapter(
                AddTransaction.this, R.layout.account_number_spinner, c,
                new String[] { DatabaseClass.KEY_ACCOUNT_NUMBER_ID },
                new int[] { R.id.accNum },
                SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

        mySpinner_for_account.setAdapter(myAdapter_for_account);

        // position of the the clicked in the spinner for account
        int position_account = mySpinner_for_account
                .getSelectedItemPosition();

        Cursor cursor2 = (Cursor) myAdapter_for_account
                .getItem(position_account);

        // holds the account number for the spinner item selected
        account_number_selected = cursor2.getString(cursor2
                .getColumnIndex(DatabaseClass.KEY_ACCOUNT_NUMBER_ID));

        // Toast.makeText(AddTransaction.this, account_number_selected,
        // Toast.LENGTH_LONG).show();
        Cursor balance = myDatabase
                .getAmountfor_Account(account_number_selected);
        balance.moveToFirst();

        /*
         * c = myDatabase.getAmountfor_Account(account_for_spiiner_account);
         * c.moveToFirst();
         */

        // get the balance as a string

        balance_in_account = balance.getString(balance // <--
                .getColumnIndex(DatabaseClass.KEY_CURRENT_BALANCE_ID));

        // Toast.makeText(AddTransaction.this, balance_in_account,
        // Toast.LENGTH_SHORT).show();

    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    myDatabase.close();

}
//在onCreate()函数中
//对于持有银行名称的微调器
Cursor=myDatabase.getData();
cursor.moveToFirst();
myAdapter=new SimpleCursorAdapter(AddTransaction.this,
R.layout.喷丝头布局,光标,
新字符串[]{DatabaseClass.KEY\u BANK\u NAME\u ID},
新int[]{R.id.bankName},
SimpleCursorAdapter.FLAG\u REGISTER\u CONTENT\u OBSERVER);
setAdapter(myAdapter);
从\u微调器获取\u数据=cursor.getString(cursor
.getColumnIndex(DatabaseClass.KEY\u BANK\u NAME\u ID));
//Toast.makeText(AddTransaction.this,从\u微调器获取\u数据,
//Toast.LENGTH_LONG).show();
//setOnItemSelectedListener(这个);
myDatabase.close();
@凌驾
已选择公共位置(适配器视图arg0、视图arg1、内部位置、,
长arg3){
//TODO自动生成的方法存根
试一试{
myDatabase.open();
int pos=位置;
Cursor Cursor=(Cursor)myAdapter.getItem(pos);
bank_name=cursor.getString(cursor//bank的名称
//精选
.getColumnIndex(DatabaseClass.KEY\u BANK\u NAME\u ID));
myAdapter=new SimpleCursorAdapter(AddTransaction.this,
R.layout.喷丝头布局,光标,
新字符串[]{DatabaseClass.KEY\u BANK\u NAME\u ID,},
新int[]{R.id.bankName},
SimpleCursorAdapter.FLAG\u REGISTER\u CONTENT\u OBSERVER);
setAdapter(myAdapter);
//Toast.makeText(AddTransaction.this,s,
//吐司。长度(短)。show();
//返回与此银行名称对应的帐号
游标c=myDatabase.getAccountData(银行名称);
c、 moveToFirst();
帐户的myAdapter\u=新的SimpleCorsAdapter(
AddTransaction.this,R.layout.account\u number\u微调器,c,
新字符串[]{DatabaseClass.KEY\u ACCOUNT\u NUMBER\u ID},
新的int[]{R.id.accNum},
SimpleCursorAdapter.FLAG\u REGISTER\u CONTENT\u OBSERVER);
设置适配器(myAdapter\u for_account);
//帐户在微调器中单击的位置
int position\u account=mySpinner\u for\u account
.getSelectedItemPosition();
Cursor cursor2=(Cursor)myAdapter\u用于\u帐户
.getItem(头寸\账户);
//保存选定微调器项目的帐号
所选帐户号=游标2.getString(游标2
.getColumnIndex(DatabaseClass.KEY\u ACCOUNT\u NUMBER\u ID));
//Toast.makeText(AddTransaction.this,已选择帐号),
//Toast.LENGTH_LONG).show();
游标平衡=myDatabase
.getAmountfor_账户(已选择账户编号);
balance.moveToFirst();
/*
*c=myDatabase.getAmountfor_Account(Account_for_spiiner_Account);
*c.移动到第一个();
*/
//将余额作为字符串获取

balance_in_account=balance.getString(balance/最终让它工作了,问题是我在同一个onItemSelected()函数中声明了两个微调器,每个微调器都应该有自己的onItemSelected函数来工作

Spinner s = (Spinner) findViewById(R.id.spinner_id);
s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){

@Override
public void onItemSelected(AdapterView adapter, View v, int i, long lng) {
//do something here
}

@Override
public void onNothingSelected(AdapterView arg0) {
//do something else
}
});