无法解析方法setVisibility(int)

时间:2015-10-14 20:11:20

标签: java android android-intent android-edittext android-radiogroup

我正在尝试在检查组中的某个单选按钮时显示一个edittext框。我收到了setVisibility的错误,并且在运行错误时它说的是int无法解除引用。

JAVA

public class MainActivity extends AppCompatActivity {

//Declared some variables here. One for each field in the form

ShareActionProvider mShareActionProvider;
String feedbackType;
String feedback;
String email;
String fName;
String lName;
String fAnswer;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    RadioGroup radiochoice=(RadioGroup) findViewById(R.id.radiochoice);
    radiochoice.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.RejectRadio) {
                R.id.RejectResponse.setVisibility(View.VISIBLE);}
            else if (checkedId == R.id.AcceptRadio) {
                R.id.RejectResponse.setVisibility(View.INVISIBLE);}
        }
    });

}

XML(这只适用于参考/评论)

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<RelativeLayout
    android:layout_width="fill_parent"
    android:orientation="vertical"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/TextViewTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:text="@string/feedbacktitle"
        android:textSize="10pt">
    </TextView>

    <!--First Name-->
    <EditText
        android:id="@+id/EditTextFirstName"
        android:layout_height="wrap_content"
        android:hint="@string/feedbackfirst"
        android:inputType="textPersonName"
        android:layout_width="fill_parent"
        android:layout_below="@+id/TextViewTitle">
    </EditText>

    <!--Last Name-->
    <EditText
        android:id="@+id/EditTextLastName"
        android:layout_height="wrap_content"
        android:hint="@string/feedbacklast"
        android:inputType="textPersonName"
        android:layout_width="fill_parent"
        android:layout_below="@id/EditTextFirstName">
    </EditText>

    <!-- Email -->
    <EditText
        android:id="@+id/EditTextEmail"
        android:layout_height="wrap_content"
        android:hint="@string/feedbackemail"
        android:inputType="textEmailAddress"
        android:layout_width="fill_parent"
        android:layout_below="@id/EditTextLastName">
    </EditText>

    <Spinner
        android:id="@+id/SpinnerFeedbackType"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:entries="@array/Types_of_Errors"
        android:layout_below="@+id/EditTextEmail">
    </Spinner>

    <EditText
        android:id="@+id/EditTextFeedbackBody"
        android:layout_height="wrap_content"
        android:hint="@string/feedbackbody"
        android:inputType="textMultiLine"
        android:lines="5"
        android:layout_width="fill_parent"
        android:layout_below="@+id/SpinnerFeedbackType">

    </EditText>

    <RadioGroup
        android:id="@+id/radiochoice"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/EditTextFeedbackBody"
        android:orientation="horizontal">

        <RadioButton
        android:id="@+id/AcceptRadio"
        android:layout_width="wrap_content"
        android:layout_marginStart="50dp"
        android:layout_height="wrap_content"
        android:text="@string/acceptbutton" />

        <RadioButton
            android:id="@+id/RejectRadio"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/rejectbutton"
            android:layout_marginStart="115dp" />
    </RadioGroup>

    <EditText
        android:id="@+id/RejectResponse"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/rejectreason"
        android:layout_marginTop="410dp"
        android:layout_alignParentEnd="true"
        android:layout_marginRight="20dp"
        android:inputType="text"/>

    <Button
        android:id="@+id/ButtonSend"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/sendform"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="590dp"
        android:onClick="submit"/>

</RelativeLayout>

1 个答案:

答案 0 :(得分:1)

你必须这样做:

//Reference rejectResponse
EditText rejectResponse = (EditText) findViewById(R.id.RejectResponse);
//Change visibility
rejectResponse.setVisibility(View.INVISIBLE);

这可能很有用:Android View