【问题标题】:Android Multiple Spinners in 1 class1 类中的 Android 多个微调器
【发布时间】:2014-06-09 17:20:39
【问题描述】:

我正在尝试在单个页面上创建 2 个微调器。我的代码在 onItemSelected 下方;

@Override

public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
        long arg3)              {

    switch(arg0.getId()) {
    case R.id.spinner1:

        switch(arg2){

        case 0:
        Toast.makeText(this,  "THIS IS SPINNER 1" ,  Toast.LENGTH_SHORT).show();
        break;
        case 1:
        Intent intent1 = new Intent(this, Screen2.class);
        startActivity(intent1);
        break;
        case 2:
        Intent intent2 = new Intent(this, Screen2.class);
        startActivity(intent2);
        break;}

    case R.id.spinner2:

        switch(arg2){
        case 0:
        Toast.makeText(this,  "THIS IS SPINNER 2" ,  Toast.LENGTH_SHORT).show();
        break;
        case 1:
        Intent intent1 = new Intent(this, Screen3.class);
        startActivity(intent1);
        break;
        case 2:
        Intent intent2 = new Intent(this, Screen3.class);
        startActivity(intent2);
        break;
        }
    }
    }

但是当我运行程序时,这些案例没有像我预期的那样响应,例如微调器 2 在它应该转到 screen2 时将其发送到 screen3

【问题讨论】:

  • "spinner 2 将其发送到 screen3"...听起来正确...检查您的代码,您告诉 spinner2 触发 Screen3.class 的意图...

标签: android spinner onitemselectedlistener


【解决方案1】:

我自己找到了答案,如下:

int a = arg0.getId();

    if (a==R.id.spinner1){
        switch(arg2) {

//Do something
                                 }

    if (a==R.id.spinner2){
        switch(arg2) {

//Do something
                                 }

【讨论】:

    猜你喜欢
    • 2012-06-02
    • 1970-01-01
    • 2020-06-20
    • 2012-04-12
    • 1970-01-01
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多