代码之家  ›  专栏  ›  技术社区  ›  Majid Ali

在android中,EditText的可见性在我的对话中不起作用

  •  0
  • Majid Ali  · 技术社区  · 6 年前

    Edittext可见性在我的代码中的对话中不起作用这里是我的xml。

      <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
    
            <RadioGroup
                android:id="@+id/radiogroup"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >
    
                <RadioButton
                    android:id="@+id/radiorefus"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="onRadioButtonClicked"
                    android:text="Outlet has refused to offer discount"
                  />
    
                <RadioButton
                    android:id="@+id/radioother"
                    android:onClick="onRadioButtonClicked"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Other" />
            </RadioGroup>
        </LinearLayout>
        <EditText
            android:layout_width="match_parent"
            android:hint="Enter short reason..."
            android:id="@+id/txtreport"
           android:visibility="gone"
            android:layout_height="wrap_content" />
    

    在这里,我的对话代码对话框将显示在点击按钮。

         Dialog dialog = new Dialog(DetailOfListCard.this);
                        dialog.setContentView(R.layout.reportdialouge);
                        dialog.show();
     inflater = LayoutInflater.from(DetailOfListCard.this);
                    view = inflater.inflate(R.layout.reportdialouge, null);
                    editText = (EditText) view.findViewById(R.id.txtreport);
                    textView = (TextView) view.findViewById(R.id.reptxt);
    

    在这里,我使用单选按钮在我的对话布局。 这里是我的java代码,我想在单选按钮的基础上设置编辑文本的可见性

     public void onRadioButtonClicked(View v){
            RadioGroup rg = (RadioGroup)view.findViewById(R.id.radiogroup);
             radioButton = (RadioButton)view.findViewById(R.id.radiorefus);
             radioButton1 = (RadioButton)view.findViewById(R.id.radioother);
    
            // Is the current Radio Button checked?
            boolean checked = ((RadioButton) v).isChecked();
    
            switch(v.getId()){
                case R.id.radiorefus:
                    Toast.makeText(DetailOfListCard.this,"detail of list",Toast.LENGTH_SHORT).show();
                    textView.setVisibility(View.INVISIBLE);
                    break;
    
                case R.id.radioother:
                   textView.setVisibility(View.VISIBLE);
                    Toast.makeText(DetailOfListCard.this,"edit text visible",Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   jitendra purohit    6 年前

    使用如下对话框初始化edittext,

    EditText et= dialog.findViewById(R.id.edittext);
    

    然后,使edittext如下所示,

    et.setVisibility(VIEW.VISIBLE);