Editext的可见性在我的

时间:2018-03-22 10:56:52

标签: android layout dialog android-edittext visibility

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 个答案:

答案 0 :(得分:0)

使用您的对话框初始化edittext,

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

,让你的edittext像这样显示,

et.setVisibility(VIEW.VISIBLE);