Sunteți pe pagina 1din 4

File xmn

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context=".MainActivity" > <TextView android:id="@+id/tvdisplay" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="THONG TIN SINH VIEN" /> <TextView android:id="@+id/tvhoten" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="HO VA TEN" android:layout_below="@+id/tvdisplay" /> <EditText android:id="@+id/ethoten" android:layout_width="150dp" android:layout_height="30dp" android:layout_toRightOf="@+id/tvhoten" /> <TextView android:id="@+id/tvmasv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="MA SV" android:layout_below="@+id/tvhoten" /> <EditText android:id="@+id/etmasv" android:layout_width="150dp" android:layout_height="30dp" android:layout_toRightOf="@+id/tvmasv" android:layout_below="@+id/tvhoten" /> <TextView android:id="@+id/tvgt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="GIOI TINH" android:layout_below="@+id/etmasv" /> <RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/group" android:layout_below="@+id/tvgt"

> <RadioButton android:id="@+id/nam" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="NAM"/> <RadioButton android:id="@+id/nu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="NU"/> <TextView android:id="@+id/tvmonhoc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="MON HOC UA THICH" android:layout_below="@+id/group" /> <CheckBox android:id="@+id/cbtoan" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TOAN" android:layout_below ="@+id/tvmonhoc" /> <CheckBox android:id="@+id/cbly" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="LY" android:layout_below ="@+id/cbtoan" /> <CheckBox android:id="@+id/cbanh" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ANH" android:layout_below ="@+id/cbly" /> <CheckBox android:id="@+id/cbtheduc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="THE DUC" android:layout_below ="@+id/cbanh" /> <CheckBox android:id="@+id/cbchuyende" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="CHUYEN DE" android:layout_below ="@+id/cbtheduc" /> <Button android:id="@+id/ok"

android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="OK" android:layout_below="@+id/cbchuyende"/> <TextView android:id="@+id/tvtb" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/ok"/> </RadioGroup> </RelativeLayout>

FILE JAVA
package conankun.baikiemtraso1; import import import import import import import import public { android.app.Activity; android.os.Bundle; android.view.View; android.widget.Button; android.widget.CheckBox; android.widget.EditText; android.widget.RadioButton; android.widget.TextView; class MainActivity extends Activity implements View.OnClickListener EditText ethoten,etmasv; CheckBox cbtoan,cbly,cbanh,cbtheduc,cbchuyende; TextView tvtb; Button ok; RadioButton nam,nu; @Override protected void onCreate(Bundle b) { super.onCreate(b); setContentView(R.layout.activity_main); ethoten=(EditText) findViewById(R.id. ethoten); etmasv=(EditText) findViewById(R.id. etmasv); cbtoan=(CheckBox) findViewById(R.id. cbtoan); cbly=(CheckBox) findViewById(R.id. cbly); cbanh=(CheckBox) findViewById(R.id.cbanh); cbtheduc=(CheckBox) findViewById(R.id. cbtheduc); cbchuyende=(CheckBox) findViewById(R.id. cbchuyende); nam=(RadioButton) findViewById(R.id. nam); nu=(RadioButton) findViewById(R.id.nu); tvtb=(TextView) findViewById(R.id. tvtb); ok=(Button) findViewById(R.id.ok); ok.setOnClickListener(this); } public void onClick(View v) { String t=null; if(ethoten.getText().toString() != null) {

t="Ho Ten: " + ethoten.getText().toString() + '\n'; } if(etmasv.getText().toString() != null) { t=t+ "Ma SV: " + etmasv.getText().toString() + '\n'; } if(nam.isChecked()) { t=t+"Gioi Tinh: "+nam.getText()+'\n'; } if(nu.isChecked()) { t=t+"Gioi Tinh: "+nu.getText()+'\n'; } if(cbtoan.isChecked()) { t=t+cbtoan.getText()+", "; } if(cbly.isChecked()) { t=t+cbly.getText()+", "; } if(cbanh.isChecked()) { t=t+cbanh.getText()+", "; } if(cbtheduc.isChecked()) { t=t+cbtheduc.getText()+", "; } if(cbchuyende.isChecked()) { t=t+cbchuyende.getText()+", "; } tvtb.setText(t); } }

S-ar putea să vă placă și