import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.TextView; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; public class demoActivity extends AppCompatActivity { @BindView(R.id.rb1) RadioButton btn1; @BindView(R.id.rb2) RadioButton btn2; @BindView(R.id.rb3) RadioButton btn3; @BindView(R.id.rb4) RadioButton btn4; @BindView(R.id.rg_appointment) RadioGroup rgAppointment; @BindView(R.id.tv1) TextView tv1; @BindView(R.id.tv2) TextView tv2; @BindView(R.id.tv3) TextView tv3; @BindView(R.id.tv4) TextView tv4; int maxIndex = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_demo); ButterKnife.bind(this); setState(maxIndex); rgAppointment.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.rb1: if (maxIndex >= 0) { tv1.setVisibility(View.VISIBLE); tv2.setVisibility(View.GONE); tv3.setVisibility(View.GONE); tv4.setVisibility(View.GONE); tv2.setText("医生"); tv3.setText("信息"); tv4.setText("预约"); //btn状态 btn2.setText("医生"); btn3.setText("确定信息"); btn4.setText("预约状态"); maxIndex = 0; } break; case R.id.rb2: if (maxIndex >= 1) { tv1.setVisibility(View.GONE); tv2.setVisibility(View.VISIBLE); tv3.setVisibility(View.GONE); tv4.setVisibility(View.GONE); tv3.setText("信息"); tv4.setText("预约"); btn3.setText("确定信息"); btn4.setText("预约状态"); maxIndex = 1; } break; case R.id.rb3: if (maxIndex >= 1) { tv1.setVisibility(View.GONE); tv2.setVisibility(View.GONE); tv3.setVisibility(View.VISIBLE); tv4.setVisibility(View.GONE); tv4.setText("预约"); btn4.setText("预约状态"); maxIndex = 2; } break; case R.id.rb4: if (maxIndex >= 3) { tv1.setVisibility(View.GONE); tv2.setVisibility(View.GONE); tv3.setVisibility(View.GONE); tv4.setVisibility(View.VISIBLE); maxIndex = 3; } break; } setState(maxIndex); } }); } public void setState(int index) { for (int i = 0; i < rgAppointment.getChildCount(); i++) { RadioButton view = (RadioButton) rgAppointment.getChildAt(i); if (i <= index) { view.setClickable(true); } else { view.setClickable(false); } } } public void setCheck(int index) { for (int i = 0; i < rgAppointment.getChildCount(); i++) { RadioButton view = (RadioButton) rgAppointment.getChildAt(i); if (i == index) { view.setChecked(true); } } } @OnClick({R.id.tv1, R.id.tv2, R.id.tv3, R.id.tv4}) public void onViewClicked(View view) { switch (view.getId()) { case R.id.tv1: maxIndex = 1; btn1.setText("1"); tv1.setText("1"); break; case R.id.tv2: maxIndex = 2; btn2.setText("2"); tv2.setText("2"); break; case R.id.tv3: maxIndex = 3; btn3.setText("3"); tv3.setText("3"); break; case R.id.tv4: maxIndex = 3; btn4.setText("4"); tv4.setText("4"); break; } setCheck(maxIndex); } } xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" tools:context="com.selfsupport.ui.demoActivity"> <RadioGroup android:id="@+id/rg_appointment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginRight="40dp" android:layout_weight="1" android:overScrollMode="never" android:scrollbars="none"> <RadioButton android:id="@+id/rb1" android:layout_width="match_parent" android:layout_height="100dp" android:layout_marginBottom="10dp" android:background="@drawable/rec_btn_selector" android:button="@null" android:checked="true" android:gravity="center" android:text="科室" android:textColor="@color/rec_btn_textcolor" android:textSize="30sp" /> <RadioButton android:id="@+id/rb2" android:layout_width="match_parent" android:layout_height="100dp" android:layout_marginTop="20dp" android:layout_marginBottom="10dp" android:background="@drawable/rec_btn_selector" android:button="@null" android:gravity="center" android:text="选择医生" android:textColor="@color/rec_btn_textcolor" android:textSize="30sp" /> <RadioButton android:id="@+id/rb3" android:layout_width="match_parent" android:layout_height="100dp" android:layout_marginTop="20dp" android:layout_marginBottom="10dp" android:background="@drawable/rec_btn_selector" android:button="@null" android:gravity="center" android:text="确认信息" android:textColor="@color/rec_btn_textcolor" android:textSize="30sp" /> <RadioButton android:id="@+id/rb4" android:layout_width="match_parent" android:layout_height="100dp" android:layout_marginTop="20dp" android:background="@drawable/rec_btn_selector" android:button="@null" android:gravity="center" android:text="预约信息" android:textColor="@color/rec_btn_textcolor" android:textSize="30sp" /> </RadioGroup> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <TextView android:id="@+id/tv1" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="科室" android:textSize="30sp"></TextView> <TextView android:visibility="gone" android:id="@+id/tv2" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="医生" android:textSize="30sp"></TextView> <TextView android:visibility="gone" android:id="@+id/tv3" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="确认信息" android:textSize="30sp"></TextView> <TextView android:visibility="gone" android:id="@+id/tv4" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="预约状态" android:textSize="30sp"></TextView> </LinearLayout> </LinearLayout>
效果图,传不上去