パッケージcom.lidaochen.test。 輸入android.content.Intent。 輸入android.net.Uri; 輸入android.os.Bundle; 輸入android.support.v7.app.AppCompatActivity。 輸入android.text.TextUtils。 輸入android.view.View。 輸入android.widget.EditText; 輸入android.widget.RadioButton; 輸入android.widget.RadioGroup; 輸入android.widget.Toast; パブリック クラス MainActivityは拡張AppCompatActivity { プライベートのEditText et_nameを。 プライベートRg_group RADIOGROUP; @Overrideは、 保護された ボイドのonCreate(バンドルsavedInstanceState){ スーパー; .onCreate(savedInstanceState) setContentView(R.layout.activity_main); // 取得のEditText制御 et_name = (のEditText)findViewById(R.id.et_name); //をRADIOGROUP制御ゲット rg_group = ;(RADIOGROUP)findViewById(R.id.rg_groupを) } // ResultActivityに実装され、計算文字ページジャンプをクリックし 、公共 のボイドクリック(ビューV) { // 1、ユーザー取得する。 文字列名= et_nameを。 。のgetText()のtoString()TRIM();. //2、どのような名前空気か否かが判定される IF (TextUtils.isEmpty(名)) { Toast.makeText(getApplicationContext()は、 "プロ、名前を入力してください" 、Toast.LENGTH_SHORT).SHOW(); を返します; } / / 3は、ユーザは、性別決意選択 INT radioBtnID = ; rg_group.getCheckedRadioButtonId() int型の性別= 0 ; スイッチ(radioBtnID) { // 選択された男性を表す ケースR.id.rb_man: 性別 = 1 ; BREAK ; // 代表女性の選ぶ ケースをR.id.rb_woman: セックス = 2 ; BREAK ; // 代表サイモン選んだ ケースR.id.rb_renyaoを: セックス。= 3 ; BREAK ; } // 。4、どのような性別選択するか否かを判断する IF(セックス== 0 ) { Toast.makeText(getApplicationContextは()、 "プロ、性別を選択..." 、Toast.LENGTH_SHORT)が.SHOW(); を返す; } // ResultActivityでページに行くには、表示しよう 意思意図= 新新意図(これを。、ResultActivityのクラス); //は名前を渡す intent.putExtra( "名称" 、名); //は性別通過 intent.putExtra( "性別" 、セックス); // 開いているアクティビティ startActivity(インテント); } }
パッケージcom.lidaochen.test。 輸入android.content.Intent。 輸入android.support.v7.app.AppCompatActivity。 輸入android.os.Bundle; 輸入android.widget.TextView。 輸入java.io.UnsupportedEncodingException。 パブリック クラス ResultActivityは延びAppCompatActivity { @Overrideが 保護 ボイドのonCreate(バンドルsavedInstanceState){ スーパー.onCreate(savedInstanceState)を、 setContentView(R.layout.activity_result)。 // 获取のTextView控件 のTextView tv_name =(TextViewの)findViewById(R.id.tv_name); のTextViewのtv_sex = (TextViewの)findViewById(R.id.tv_sex); のTextViewのtv_rp = (TextViewの)findViewById(R.id.tv_rp); // データがそれに渡されるMainActivity =テントテントそのgetIntent(); // 取得します名前と性別値の 文字列名= intent.getStringExtra( "名前" ); int型性別= intent.getIntExtra( "セックス"、0 ); // 表示データ tv_name.setText(名); バイト []バイト= NULL ; スイッチ(性別) { ケース 1。: tv_sex.setText( "男" ); 試す{ バイト = name.getBytes( "GBKを" )。 } キャッチ(にUnsupportedEncodingException電子){ e.printStackTrace(); } ブレーク; ケース 2 : tv_sex.setText( "女" )。 試す{ バイト = name.getBytes( "UTF-8" )。 } キャッチ(にUnsupportedEncodingException電子){ e.printStackTrace(); } BREAK ; ケース 3 : tv_sex.setText( "サイモン" ); 試み{ バイト =のname.getBytes( "ISO-8859-1" ); } キャッチ(にUnsupportedEncodingException E){ e.printStackTrace() ; } BREAK ; デフォルト: BREAK ; } // 文字の計算結果 int型 0 =合計; 用(バイトB:バイト) { int型ナンバー= B&0xFFで、 合計 + = ナンバー; } // スコアを取得 int型スコア= Math.abs(合計)100%を、 IF(スコア> 90 ) { tv_rp.setText(「あなたのキャラクターは、あなたの家は非常に良いです墓はそれをすべてを吸う取る"!); } 他の IF(スコア> 80 ) { tv_rp.setText( "あなたのキャラクターもできます"!;) } 他の IF(スコア> 60 ) { (tv_rp.setTextあなたを"ただ文字を「合格!); } それ以外の { Tv_rp.setText(「回もあなたのキャラクターは、あなたがああ努力する必要があります!」); } } }