2

我试图在我的应用程序中从微调器中选择项目时隐藏或显示编辑文本。这里是代码,请建议如何修复它

 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) {

     }
 });
4

5 回答 5

2
rlDate.setVisibility(View.GONE);

将使视图“消失”。

于 2013-04-15T10:24:19.263 回答
1

希望您的微调器及其点击事件运行良好。然后您可以添加以下代码来禁用或启用编辑文本:

     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可见性。希望这有效..

于 2013-04-15T10:26:58.767 回答
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);

        }
    });

希望这对您有所帮助 - 如果您仍然遇到此问题 - 或其他任何目前遇到此问题的人。

干杯!

于 2017-12-14T13:11:31.910 回答
-1
EditText ta=(EditText)findviewById(R.id.***);
ta.setVisibility(View.GONE);
于 2014-03-13T14:27:15.193 回答
-1

下面的代码为 hode Edittext

EditText.setVisibility(View.GONE);
于 2013-04-15T10:25:41.737 回答