一起引用两个微调器?

时间:2015-05-22 22:08:11

标签: java android

所以基本上我有两个旋转器,其中一个是星期一,星期二,星期三等...另一个包含四个数字0732,3735,0736和0737.是否可以添加一个if语句说位置1(星期一)+位置2(0736)=新变量Mon36。任何帮助将不胜感激?

    final Spinner spinner1 = (Spinner) findViewById(R.id.sp_dotw);
    final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.dotw_array, R.layout.custom_spinner);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner1.setAdapter(adapter);

    spinner1.setOnItemSelectedListener(
            new OnItemSelectedListener() {

                public void onItemSelected(
                        AdapterView<?> parent, View view, int position, long id) {

                    showToast("spinnerdotw: position= " + position + "id=" + id);
                }

                public void onNothingSelected(AdapterView<?> adapterView) {
                    showToast("No Dotw selected");
                }


            });

    final Spinner spinner2 = (Spinner) findViewById(R.id.sp_pg);

    final ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this,
            R.array.pg_array, R.layout.custom_spinner);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner2.setAdapter(adapter2);
    final String porition1;


    spinner2.setOnItemSelectedListener(
            new OnItemSelectedListener() {

                public void onItemSelected(
                        AdapterView<?> parent, View view, int position, long id) {

                   spinner2position = position;

                   }

                public void onNothingSelected(AdapterView<?> adapterView) {
                    showToast("No Pg selected");

                }

            });

 private void spinnerPos() {
    if (spinner1position + spinner2position == 0) ;
    {
        TextView sonyR = (TextView) findViewById(R.id.textView14);
        sonyR.setText(" sunday and pg32 have been selected ");

        Log.i(String.valueOf(sonyR), "pos");

    }if
      (spinner1position + spinner2position == 1)
        {
        TextView sonyR = (TextView) findViewById(R.id.textView14);
        sonyR.setText(" Monday and pg32 have been selected ");

        Log.i(String.valueOf(sonyR), "pos");
    }

}

1 个答案:

答案 0 :(得分:0)

您的代码中存在一些问题:

OnItemSelectedListener()的{​​{1}},,您没有设置spinner1 ,因此永远不会更新:

spinner1position

您也{strong>永远不会在spinner1.setOnItemSelectedListener( new OnItemSelectedListener() { public void onItemSelected( AdapterView <? > parent, View view, int position, long id) { showToast("spinnerdotw: position= " + position + "id=" + id); } \\ ... }); 中致电spinnerPos() ,因此用户界面上的文字永远不会更新。

OnItemSelectedListener()的更好版本就是:

OnItemSelectedListener

spinner1.setOnItemSelectedListener( new OnItemSelectedListener() { public void onItemSelected(AdapterView <? > parent, View view, int position, long id) { spinner1position = position; spinnerPos(); showToast("spinnerdotw: position= " + position + "id=" + id); } \\ ... }); 相同。

方法spinner2中也有一些错误:

spinnerPos()

if (spinner1position + spinner2position == 0) ; { TextView sonyR = (TextView) findViewById(R.id.textView14); sonyR.setText(" sunday and pg32 have been selected "); Log.i(String.valueOf(sonyR), "pos"); } 子句后面的分号看起来像拼写错误。你的条件也没有多大意义 - 你必须独立地看待每个价值,而不是总和。