Android Elementary School arithmetic

Source: Internet
Author: User

Android activity:

Package com.example.count_number;


Import Android.os.Bundle;
Import android.app.Activity;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.EditText;



public class Mainactivity extends Activity {

private int x,y;//used to generate X, Y
private int fhao;//used to generate symbols

Private EditText t1,t2,t3;
Private Button B1;
private int answer,sure;
Private EditText e1,e2;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
x = (int) (Math.random () *9) +1; Cannot appear 0
y = (int) (Math.random () *9) +1;
fhao= (int) (Math.random ()) +1;
t1= (EditText) Findviewbyid (R.ID.ET1);
T2= (EditText) Findviewbyid (R.id.et2);
t3= (EditText) Findviewbyid (R.ID.ET3);
b1= (Button) Findviewbyid (R.id.button1);
e1= (EditText) Findviewbyid (R.ID.EDITTEXT1);
E2= (EditText) Findviewbyid (R.ID.EDITTEXT2);
Show
T1.settext (x);
Switch (Fhao)
{
Case 1:
T2.settext ("+");
Sure=x+y;
Break
Case 2:
T2.settext ("-");
Sure=x-y;
Break
Case 3:
T2.settext ("*");
Sure=x*y;
Break
Case 4:
T2.settext ("/");
sure=x/y;
Break
}
T3.settext (y);

Enter and determine the answer
B1.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View arg0) {
TODO auto-generated Method Stub
Answer=integer.parseint (E1.gettext (). toString ());
if (answer==sure)
{
E2.settext ("correct");
}
if (answer!=sure)
{
E2.settext ("error");
}
}
});

}

}
Android XML file

<relativelayout 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:paddingbottom= "@dimen/activity_vertical_margin"
android:paddingleft= "@dimen/activity_horizontal_margin"
android:paddingright= "@dimen/activity_horizontal_margin"
android:paddingtop= "@dimen/activity_vertical_margin"
Tools:context= ". Mainactivity ">

<edittext
Android:id= "@+id/et4"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_alignparentbottom= "true"
Android:layout_centerhorizontal= "true"
android:layout_marginbottom= "23DP"/>

<edittext
Android:id= "@+id/et1"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_alignleft= "@+id/edittext1"
Android:layout_alignparenttop= "true"/>

<edittext
Android:id= "@+id/et2"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_alignbaseline= "@+id/textview1"
Android:layout_alignbottom= "@+id/textview1"
android:layout_alignright= "@+id/textview4"/>

<edittext
Android:id= "@+id/et3"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_alignbaseline= "@+id/textview1"
Android:layout_alignbottom= "@+id/textview1"
android:layout_marginleft= "16DP"
android:layout_torightof= "@+id/edittext1"/>

<edittext
Android:id= "@+id/edittext1"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_alignparentleft= "true"
android:layout_below= "@+id/textview1"
android:layout_margintop= "145DP"
android:ems= "Ten"/>

<textview
Android:id= "@+id/textview3"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_alignbottom= "@+id/edittext1"
android:layout_alignleft= "@+id/edittext1"
Android:layout_marginbottom= "75DP"
android:text= "Your input:"/>

<edittext
Android:id= "@+id/edittext2"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_alignparentbottom= "true"
Android:layout_marginbottom= "21DP"
android:layout_toleftof= "@+id/textview2"
Android:ems= "Ten" >

<requestfocus/>
</EditText>

<textview
Android:id= "@+id/textview5"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_above= "@+id/textview4"
android:layout_alignleft= "@+id/edittext2"
Android:layout_marginbottom= "15DP"
Android:text= "is correct:"/>

<button
Android:id= "@+id/button1"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_above= "@+id/textview5"
Android:layout_centerhorizontal= "true"
Android:layout_marginbottom= "32DP"
android:text= "Submit Answer"/>

</RelativeLayout>

This is a simple pupil arithmetic app

Android Elementary School arithmetic

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.