Calculate the value of two couples ' marriage according to their names

Source: Internet
Author: User

The background image itself is replaced or changed to a background color.

Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.os.Bundle;Importandroid.text.TextUtils;ImportAndroid.view.View;ImportAndroid.widget.EditText;ImportAndroid.widget.Toast; Public classMainactivityextendsActivity {PrivateEditText Et_boyname; PrivateEditText Et_girlname; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Et_boyname= (EditText) This. Findviewbyid (R.id.et_boyname); Et_girlname= (EditText) This. Findviewbyid (R.id.et_girlname); }     Public voidBtn_calc (view view) {String Boyname=Et_boyname.gettext (). toString (); String Girlname=Et_girlname.gettext (). toString (); if(Textutils.isempty (boyname)) {Toast.maketext ( This, "The boy's name cannot be empty", 0). Show (); Et_boyname.setfocusableintouchmode (true);            Et_boyname.requestfocus ();            Et_boyname.requestfocusfromtouch (); return; }        if(Textutils.isempty (girlname)) {Toast.maketext ( This, "The girl name cannot be empty", 0). Show (); Et_girlname.setfocusableintouchmode (true);            Et_girlname.requestfocus ();            Et_girlname.requestfocusfromtouch (); return; } Intent Intent=NewIntent ( This, Secondactivity.class); Intent.putextra ("Boyname", Boyname); Intent.putextra ("Girlname", Girlname);    StartActivity (Intent); }}

mport android.app.Activity;Importandroid.content.Intent;ImportAndroid.os.Bundle;ImportAndroid.widget.TextView; Public classSecondactivityextendsActivity {PrivateTextView Tv_result; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_second); Tv_result= (TextView) This. Findviewbyid (R.id.tv_result); Intent Intent=getintent (); if(Intent! =NULL) {String boyname= Intent.getstringextra ("Boyname"); String Girlname= Intent.getstringextra ("Girlname"); intHashcode = Boyname.hashcode () +Girlname.hashcode (); Random Random=NewRandom (hashcode); intran = random.nextint (100); Tv_result.settext (Boyname+ "and" + Girlname + "of the Marriage value:" +ran); }    }}
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "Vertical"Tools:context=". Mainactivity "android:gravity= "Center_vertical"Android:background= "@drawable/aiqing" > <EditText Android:id= "@+id/et_boyname"Android:layout_width= "Match_parent"Android:layout_height= "40DP"Android:hint= "Please enter the boy's name"/> <EditText android:layout_margintop= "30DP"Android:id= "@+id/et_girlname"Android:layout_width= "Match_parent"Android:layout_height= "40DP"Android:hint= "Please enter girl name"/> <Button android:layout_margintop= "30DP"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:layout_gravity= "Center_vertical"android:gravity= "Center_vertical|center_horizontal"Android:onclick= "Btn_calc"Android:text= "Start Calculating marriage"/></linearlayout>

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:background= "@drawable/jieguo"android:orientation= "Vertical"Tools:context=". Secondactivity "> <TextView android:gravity= "Center_vertical"Android:id= "@+id/tv_result"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:textcolor= "#ff0000"android:textsize= "18SP"Android:text= "Marriage value"/></linearlayout>

Run:

Calculate the value of a two-person marriage based on a male or female name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.