本文介绍了Android微调器:执行所选项目并将其与另一个微调器进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用2个微调器,我想在我的按钮单击中执行此操作,例如在Visual Studio中像这样

I'm working with 2 spinner in my app, and I want to do this operation in my button click for example like this in visual studio

if ((spin1.text = "bla bla bla") && (spin2. text = "ho ho ho"))
    {
       text1.text = result;
    }

您是否有任何想法在android中执行此操作?谢谢.

Do you have any idea to perform this operation in android? thanks.

使用此代码已解决!!

SOLVED WITH THIS CODE!!

spin1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
    {
        @Override
        public void onItemSelected(AdapterView<?> parent, View seletedItem, int pos, long id)
        {
            Object item = parent.getItemAtPosition(pos);
            value1 = item.toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent)
        {

        }
    });

    spin2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
    {
        @Override
        public void onItemSelected(AdapterView<?> parent, View selectedItem, int pos, long id)
        {
            Object item = parent.getItemAtPosition(pos);
            value2 = item.toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent)
        {

        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

public void count(View v)
{
    if(value1.equals("Depok") && value2.equals("Jakarta"))
    {
        hasil.setText("SUCCESS");
    }
}

推荐答案

首先,您必须正确地从微调器中检索文本,您这样做了吗?如果没有,这是这样做的方法:

First you have to retrieve the text from the spinner correctly, did you do that?If not, this is how to do it:

假设您呼叫了微调器spinner.

Spinner mySpinner = (Spinner)findViewById(R.id.spinner);
String txtFromSpinner = mySpinner.getSelectedItem().toString();

比较时,请从微调器中取出字符串,并将其与某些字符串进行比较.

When comparing, take the string from the spinner and compare it with some string.

if (txtFromSpinner.equals("bla bla bla") && txtFromSpinner2.equals("ho ho ho")
{
   Log.E("Well done sir.","Comparison complete!");
   //Code
}

祝你好运.

这篇关于Android微调器:执行所选项目并将其与另一个微调器进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 17:33