package com.lidaochen.test; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.view.View; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private EditText et_name; privateRg_group RadioGroup; @Override protected void the onCreate (the Bundle savedInstanceState) { Super .onCreate (savedInstanceState); the setContentView (R.layout.activity_main); // Get EditText control et_name = (EditText) the findViewById (R.id.et_name); // Get RadioGroup control rg_group = (RadioGroup) the findViewById (R.id.rg_group); } // click implemented calculation character page jump to ResultActivity public void the click (View V) { // . 1, to obtain the user String name = et_name. . getText () toString () the TRIM ();. //2, what name is determined whether the air IF (TextUtils.isEmpty (name)) { Toast.makeText (getApplicationContext (), "pro, enter the name ..." , Toast.LENGTH_SHORT) the .Show (); return ; } / / 3, the user selects the gender determination int radioBtnID = rg_group.getCheckedRadioButtonId (); int sex = 0 ; Switch (radioBtnID) { // representing the selected male Case R.id.rb_man: sex =. 1 ; BREAK ; // representatives choose a female caseR.id.rb_woman: Sex = 2 ; BREAK ; // representatives chose Simon Case R.id.rb_renyao: Sex =. 3 ; BREAK ; } // . 4, determines whether to select what gender IF (Sex == 0 ) { Toast.makeText (getApplicationContext (), "pro, select gender ..." , Toast.LENGTH_SHORT) the .Show (); return ; } // Go to page with ResultActivity intended to display the intent intent = new new the intent ( the this., ResultActivity class ); // pass the name intent.putExtra ( "name" , name); // pass gender intent.putExtra ( "Sex" , Sex); // open Activity startActivity (the Intent); } }
package com.lidaochen.test; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; import java.io.UnsupportedEncodingException; public class ResultActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_result); // 获取TextView控件 TextView tv_name =(The TextView) the findViewById (R.id.tv_name); the TextView tv_sex = (the TextView) the findViewById (R.id.tv_sex); the TextView tv_rp = (the TextView) the findViewById (R.id.tv_rp); // get the data passed to it MainActivity = Intent the Intent its getIntent (); // Get the name and sex value String name = intent.getStringExtra ( "name" ); int sex = intent.getIntExtra ( "sex", 0 ); // display data tv_name.setText (name ); byte [] bytes = null ; Switch (Sex) { Case . 1: tv_sex.setText("男"); try { bytes = name.getBytes("gbk"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } break; case 2: tv_sex.setText("女"); try { bytes = name.getBytes("utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace (); } BREAK ; Case . 3 : tv_sex.setText ( "Simon" ); the try { bytes = name.getBytes ( "ISO-8859-1" ); } the catch (UnsupportedEncodingException E) { e.printStackTrace (); } BREAK ; default : BREAK ; } // calculation result of the character int Total = 0 ; for ( byte B: bytes) { int= b & 0xFF Number The ; Total + = Number The; } // get score int Score = Math.abs (Total)% 100 ; IF (Score> 90 ) { tv_rp.setText ( "Your character is very good, your home graves to take smoke it all "! ); } the else IF (Score> 80 ) { tv_rp.setText ( " your character can also "! ); } the else IF (Score> 60 ) { tv_rp.setText ( " your just pass the character "!); } The else { Tv_rp.setText ( "your character too times, you need to work hard ah!" ); } } }