Android realizes the three-level linkage of colleges and departments for your reference. The specific contents are as follows
Design a registration page
Registration items: user name, password, student number, gender, hobby, college, department and major.
Specific requirements are as follows
1. Student ID can only enter numbers
2. The password box should be hidden, between 8-24 digits
3. The radio box is used for gender. Male is selected by default
4. Like to use multiple selection boxes. The second option is selected by default
5. The drop-down list box is used for selecting colleges, departments and majors (first college, then department, and finally major. It is required that the majors of colleges and departments are linked. For example, if the computer college is selected, there can only be several departments of the college in the second series table box, if a department is selected, there can only be the corresponding majors of the Department in the third specialty table box)
6. Click the registration button to display all registration information in textview, and use toast to display all registration information at the same time
design sketch:
Click the registration button to display all registration information in textview, and use toast to display all registration information at the same time
activity_ main. XML code:
<?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="vertical"
android:gravity="center"
tools:context=".MainActivity">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Android: text = "user name"
android:textSize="18dp"
android:background="#E91E63"
android:padding="8dp"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edt1"
Android: hint = "please enter user name"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Android: text = "password"
android:textSize="18dp"
android:background="#E91E63"
android:padding="8dp"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edt2"
Android: hint = "please enter password"
android:inputType="numberPassword"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Android: text = "student ID"
android:textSize="18dp"
android:background="#E91E63"
android:padding="8dp"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edt3"
Android: hint = "please enter student number"
android:inputType="number"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Android: text = "gender"
android:textSize="18dp"
/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rg1"
android:orientation="vertical">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rb1"
Android: text = "male"
android:checked="true"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rb2"
Android: text = "female"
/>
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Android: text = "hobbies"
android:textSize="18dp"
android:layout_marginLeft="30dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Android: text = "singing"
android:id="@+id/cb1"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Android: text = "dance"
android:checked="true"
android:id="@+id/cb2"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Android: text = "calligraphy"
android:id="@+id/cb3"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Android: text = "College"
android:textSize="18dp"
android:background="#4CAF50"
android:padding="8dp"
/>
<Spinner
android:id="@+id/sp1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Android: text = "system"
android:textSize="18dp"
android:background="#4CAF50"
android:padding="8dp"
/>
<Spinner
android:id="@+id/sp2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Android: text = "professional"
android:textSize="18dp"
android:background="#4CAF50"
android:padding="8dp" />
<Spinner
android:id="@+id/sp3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Android: text = "register" / >
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Android: text = "Cancel" / >
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/id1"
android:gravity="center"
android:background="@color/colorAccent"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/id2"
android:gravity="center"
android:background="#FFEB3B"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/id3"
android:gravity="center"
android:background="#71BFE3"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
code:
package com.example.test;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.provider.MediaStore;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Spinner sp1,sp2,sp3;
Button btn1;
EditText edt1,edt2,edt3;
RadioGroup rg1;
CheckBox cb1,cb2,cb3;
TextView id1,id2,id3;
static int index;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Final string [] college = {"School of mathematics and statistics", "School of chemical materials and Engineering", "School of light industry science and technology", "School of e-commerce and logistics", "School of ecological environment", "School of computer"};
final String [][]depart=
{
{"Department of Public Mathematics", "Department of Applied Statistics", "Department of economic statistics", "Department of mathematics and Applied Mathematics"},
{"Department of Chemistry", "Department of materials science and Engineering", "Department of cosmetics"},
{"Department of Applied Chemistry", "Department of bioengineering"},
{"Department of logistics management", "Department of information management"},
{"Department of environmental science and Engineering"},
{computer department}
};
final String [][][]major=
{
{{"information and computing science"}, {"Applied Statistics"}, {"economic statistics"}, {"data science and big data technology"}},
{{"chemical technology and Engineering"}, {"polymer materials and Engineering", "functional materials"}, {"cosmetic technology and Engineering"},
{{"Chemistry"}, {"bioengineering"}},
{{"logistics management", "supply chain management"}, {"e-commerce", "information management and information system"}},
{{"environmental science and Engineering"}},
{{"computer science and technology", "software engineering", "Internet of things Engineering"}}
};
ArrayAdapter<String> colAdapter=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,college);
ArrayAdapter<String> depAdapter=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,depart[0]);
ArrayAdapter<String> morAdapter=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,major[0][0]);
edt1=(EditText)findViewById(R.id.edt1);
edt2=(EditText)findViewById(R.id.edt2);
edt3=(EditText)findViewById(R.id.edt3);
rg1=(RadioGroup) findViewById(R.id.rg1);
cb1=(CheckBox)findViewById(R.id.cb1);
cb2=(CheckBox)findViewById(R.id.cb2);
cb3=(CheckBox)findViewById(R.id.cb3);
sp1=(Spinner)findViewById(R.id.sp1);
sp2=(Spinner)findViewById(R.id.sp2);
sp3=(Spinner)findViewById(R.id.sp3);
btn1=(Button)findViewById(R.id.btn1);
id1=(TextView)findViewById(R.id.id1);
id2=(TextView)findViewById(R.id.id2);
id3=(TextView)findViewById(R.id.id3);
sp1.setAdapter(colAdapter);
sp1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
index=position;
ArrayAdapter<String> depAdapter=new ArrayAdapter<String>(MainActivity.this,R.layout.support_simple_spinner_dropdown_item,depart[position]);
sp2.setAdapter(depAdapter);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
sp2.setAdapter(depAdapter);
sp2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
ArrayAdapter<String> morAdapter=new ArrayAdapter<String>(MainActivity.this,R.layout.support_simple_spinner_dropdown_item,major[index][position]);
sp3.setAdapter(morAdapter);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String likes=" ";
String name=edt1.getText().toString();
String password=edt2.getText().toString();
String num=edt3.getText().toString();
String STR1 = "user name:" + name + "\ n" + "password:" + password + "\ n" + "student number:" + num;
String str2=" ";
if(password.length()<8||password.length()>24)
{
Toast. Maketext (mainactivity. This, "password needs 8-24 digits", toast. Length_short) show();
}
else{
id1.setText(str1);
}
for(int i=0;i<rg1.getChildCount();i++)
{
RadioButton r=(RadioButton)rg1.getChildAt(i);
if(r.isChecked())
{
STR2 = "gender:" + r.gettext() toString();
id2.setText(str2);
break;
}
}
if(cb1.isChecked())
{
likes=likes+cb1.getText().toString();
}
if(cb2.isChecked())
{
likes=likes+cb2.getText().toString();
}
if(cb3.isChecked())
{
likes=likes+cb3.getText().toString();
}
"STR + =" likes1 + "\ n + likes3": getSelectedItem(). Tostring() + "\ n" + "system:" + SP2 getSelectedItem(). Tostring() + "\ n" + "major:" + SP3 getSelectedItem(). toString();
Toast.makeText(MainActivity.this,str1+"\n"+str2+"\n"+str3,Toast.LENGTH_SHORT).show();
id3.setText(str3);
}
});
}
}
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support developpaer.