라디오버튼 클릭시 각각 다른 텍스트뷰 출력
조회수 2051회
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="월세"
android:id="@+id/etMr"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:textSize="30dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="전세"
android:id="@+id/etDps"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/radioButton"
android:textSize="30dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="매매"
android:id="@+id/etSp"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/radioButton"
android:textSize="30dp"/>
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="월세"
android:textSize="30dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="보증금"
android:textSize="20dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:hint="금액 입력"
android:id="@+id/etPrice"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="만원"
android:textSize="30dp"
android:layout_alignParentRight="true"
android:layout_weight="1" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="월세"
android:textSize="20dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:hint="금액 입력"
android:id="@+id/etmonthly_rent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="만원"
android:textSize="30dp"
android:layout_alignParentRight="true"
android:layout_weight="1" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="전세"
android:textSize="30dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="전세금"
android:textSize="20dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:hint="금액 입력"
android:id="@+id/etDeposit"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="만원"
android:textSize="30dp"
android:layout_alignParentRight="true"
android:layout_weight="1" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="매매"
android:textSize="30dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="매매금"
android:textSize="20dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:hint="금액 입력"
android:id="@+id/etSaleprice"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="만원"
android:textSize="30dp"
android:layout_alignParentRight="true"
android:layout_weight="1" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="입주금"
android:textSize="20dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:hint="금액 입력"
android:id="@+id/etIpjugeum"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="만원"
android:textSize="30dp"
android:layout_alignParentRight="true"
android:layout_weight="1" />
</LinearLayout>
위에 코드에 라디오 버튼3개가 있는데요. 라디오버튼을 각각 클릭시 다른 텍스트뷰랑 에디트뷰를 출력하고 싶습니다. 월세라는 라디오버튼을 클릭하면
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="보증금"
android:textSize="20dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:hint="금액 입력"
android:id="@+id/etPrice"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="만원"
android:textSize="30dp"
android:layout_alignParentRight="true"
android:layout_weight="1" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="월세"
android:textSize="20dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:hint="금액 입력"
android:id="@+id/etmonthly_rent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="만원"
android:textSize="30dp"
android:layout_alignParentRight="true"
android:layout_weight="1" />
</LinearLayout>
이부분들만 화면에 보이고 전세를 클릭하면 전세부분만 보이게 하고 싶습니다.
처음에는 안보이다가 라디오버튼을 클릭했을대 각기 다른텍스트를 보이게 하려면 어떻게 해야하나요?
-
(•́ ✖ •̀)
알 수 없는 사용자
1 답변
-
여러 뷰들의 묶음을 동적으로 노출하고, 숨기는 부분을 처리하고 싶다면 각 뷰들을 하나의 뷰그룹으로 접근할 수 있게 만드는 것이 좋습니다. (아래는 참고용 코드)
<LinearLayout android:id="전세"> ... </LinearLayout> <LinearLayout android:id="월세"> ... </LinearLayout>
위와 같이 뷰그룹을(참고용 코드에서는 LinearLayout을 사용했지만 이 부분은 UI에 맞게 선택하세요) 만들고 내부에 각각의 뷰들을 배치한 후
findViewById(R.id.전세).setVisibility(View.VISIBLE)
또는findViewById(R.id.월세).setVisibility(View.GONE)
와 같이 처리를 하면 됩니다.라디오 버튼에 대한 클릭 이벤트 처리는 RadioGroup의
.setOnCheckedChangeListener()
함수를 이용하세요. (아래 링크 참고)-
(•́ ✖ •̀)
알 수 없는 사용자
-
댓글 입력