Android game development system control-EditText

Source: Internet
Author: User

Android game development system control-EditText

EditText (input box) is a common component used to interact with users. It is often used when logging on to a game and entering account and password information.

Create the project "EditTextProject"

Function: Enter the content in the input box and display it in TextView.

Project running result:

 








 

The project source code is as follows:

Main. xml (layout file)

[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical">
 
<TextView
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello"
Android: id = "@ + id/TV"
/>
<EditText
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: hint = "prompt message"
Android: id = "@ + id/et"
/>
<Button
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "Get EditText content! "
Android: id = "@ + id/btn"
/>
 
</LinearLayout>
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical">

<TextView
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello"
Android: id = "@ + id/TV"
/>
<EditText
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: hint = "prompt message"
Android: id = "@ + id/et"
/>
<Button
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "Get EditText content! "
Android: id = "@ + id/btn"
/>

</LinearLayout>

String. xml

[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
 
<String name = "hello"> Hello World, EditTextProject </string>
<String name = "app_name"> EditTextProject </string>

</Resources>
<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>

<String name = "hello"> Hello World, EditTextProject </string>
<String name = "app_name"> EditTextProject </string>

</Resources>

 

EditTextProject. java

[Java]
Package com. editText;
 
Import android. app. Activity;
Import android. OS. Bundle;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. Button;
Import android. widget. EditText;
Import android. widget. TextView;
 
Public class EditTextProject extends Activity implements OnClickListener {
Private EditText et; // creates an object for text editing.
Private Button btn;
Private TextView TV;

/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Et = (EditText) findViewById (R. id. et); // edit the instantiated text
Btn = (Button) findViewById (R. id. btn );
Btn. setOnClickListener (this); // register the listener
TV = (TextView) findViewById (R. id. TV );

}
 
Public void onClick (View v ){
If (v = btn ){
// Obtain the text content in EditText
String str = et. getText (). toString ();
// Let TextView display the obtained EditText content str
TV. setText (str );
}

}

}



Author: wwj

Related Article

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.