简体   繁体   English

[android] spinner onItemSelected和可见性

[英][android]spinner onItemSelected and visibility

I try to make editText and TextView visibility triggered by select item on spinner. 我试图通过微调器上的选择项来使editText和TextView可见性。 I use the code below but it does not work. 我使用下面的代码,但不起作用。 The item should be gone at first time and when i select item on the spinner editText and TextView will show up. 该项目应该在第一次使用时消失,当我在微调器上选择项目时,editText和TextView将显示出来。 What happen is The editText and TextView show up at the first time and when i select another item the editText and TextView won't gone. 发生的是第一次显示editText和TextView,当我选择另一个项目时,editText和TextView不会消失。

ArrayAdapter<String> adapter2 = new ArrayAdapter<String>
    (this, android.R.layout.simple_spinner_dropdown_item, SP_KMA);
    Spiner_KMA.setAdapter(adapter2);

    Spiner_KMA.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            // TODO Auto-generated method stub
            String select = arg0.getSelectedItem().toString();
            if(select.equalsIgnoreCase("ganti meter")){
                txt_ganti_meter.setVisibility(1);
                et_id_ganti_meter.setVisibility(1);
            }else{
                txt_ganti_meter.setVisibility(2);
                et_id_ganti_meter.setVisibility(2);
            }

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }

    });

Set visibility like this 这样设置可见度

txt_ganti_meter.setVisibility(View.VISIBLE);

txt_ganti_meter.setVisibility(View.GONE);

currently u are passing wrong constant values to setVisibility for making a View INVISIBLE or VISIBLE : 当前,您正在将错误的常量值传递给setVisibility以使View不INVISIBLEVISIBLE

as in View class : 如在View类中:

Constant Value: 2 (0x00000002) :The view is not important for accessibility. 常量值:2(0x00000002):视图对于可访问性并不重要。

and

Constant Value: 1 (0x00000002) :The view is important for accessibility. 常量值:1(0x00000002):视图对于可访问性很重要。

u will pass 0 and 4 to make View Visible or InVisible 您将传递04以使“可见”或“不可见”

For VISIBLE : setVisibility(0) or setVisibility(View.VISIBLE) 对于VISIBLE: setVisibility(0)setVisibility(View.VISIBLE)

For INVISIBLE : setVisibility(4) or setVisibility(View.INVISIBLE) 对于INVISIBLE: setVisibility(4)setVisibility(View.INVISIBLE)

For GONE : setVisibility(8) or setVisibility(View.GONE) 对于GONE: setVisibility(8)setVisibility(View.GONE)

根据需要使用此txt_ganti_meter.setVisibility(View.INVISIBLE)或txt_ganti_meter.setVisibility((View.VISIBLE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM