下面项目的架构是什么?为什么那么复杂?
原本想跟着实例学习,没想到实例是那么复杂,而且看起来找不到逻辑,学习编程真的很难啊!
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private RadioGroup rg_root;
private Button bt_look;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rg_root = findViewById(R.id.rg_root);
bt_look = findViewById(R.id.bt_look);
bt_look.setOnClickListener(this);
rg_root.check(R.id.rb_one);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.bt_look:
if (rg_root.getCheckedRadioButtonId() == R.id.rb_one){
Toast.makeText(this,"第一项",Toast.LENGTH_LONG).show();
}else if (rg_root.getCheckedRadioButtonId() == R.id.rb_two){
Toast.makeText(this,"第二项",Toast.LENGTH_LONG).show();
}else if (rg_root.getCheckedRadioButtonId() == R.id.rb_three){
Toast.makeText(this,"第三项",Toast.LENGTH_LONG).show();
}
break;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RadioGroup
android:id="@+id/rg_root"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/rb_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一项"/>
<RadioButton
android:id="@+id/rb_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第二项"/>
<RadioButton
android:id="@+id/rb_three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第三项"/>
</RadioGroup>
<Button
android:id="@+id/bt_look"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="看结果"/>
</LinearLayout>