2013-04-15 255 views
2

我試圖隱藏或顯示在我的app.Here從微調選擇項目編輯文本是代碼請建議如何解決它隱藏和取消隱藏的EditText

ArrayAdapter adapter1 = ArrayAdapter.createFromResource(
      this, R.array.country_array, android.R.layout.simple_spinner_item); 
     adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
     spinner1.setAdapter(adapter1); 
spinner1.setOnItemSelectedListener(new OnItemSelectedListener() { 
    @Override 
    public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) { 
     rlDate.setVisibility(View.VISIBLE); 
     rlTime.setVisibility(View.VISIBLE); 

    } 

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

    } 
}); 
+0

你到底想要做什麼??以上輸出的代碼是什麼? – AndiM

回答

2
rlDate.setVisibility(View.GONE); 

將使視圖「消失'。

+0

根據所選物品調用上述方法隱藏或顯示編輯框 –

-1

低於HODE EDITTEXT代碼

EditText.setVisibility(View.GONE); 
1

希望你的微調和其click事件worls fine..Then您可以添加下面的代碼來禁用或ebable的EditText上:

 int count = 0; 
     spinner1.setOnItemSelectedListener(new OnItemSelectedListener() { 
      @Override 
      public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) { 
      **if(count == 0){ 
       rlDate.setVisibility(View.VISIBLE); 
       count == 1; 
      }else{ 
       rlDate.setVisibility(View.INVISIBLE); 
       count = 0; 
     }** 
    } 
    }); 

這將設置edittext visibility每當你點擊spinner.Hope這個作品..

+1

不錯的作品,謝謝 –

-1
EditText ta=(EditText)findviewById(R.id.***); 
ta.setVisibility(View.GONE); 
0

這是我如何實現我認爲你在嘗試:

spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 

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

      if (Objects.equals(spinner1.getSelectedItem().toString(), "<item_text_value>")) { 

       rlDate.setVisibility(View.VISIBLE); 
       rlTime.setVisibility(View.VISIBLE); 

      } 
     } 

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

      rlDate.setVisibility(View.GONE); 
      rlTime.setVisibility(View.GONE); 

     } 
    }); 

希望這個幫助你 - 如果你仍然有這個問題 - 或任何其他人目前擁有它。

乾杯!