歡迎大家在這裡學習編輯框EditView!下面是我們給大家整理出來的精彩內容。希望大家在這裡學習!
- public class EditTextActivity extends Activity {
-
- Context mContext = null;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- setContentView(R.layout.editview);
- mContext = this;
- //帳號
- final EditText editText0 = (EditText)findViewById(R.id.editview0);
- //密碼
- final EditText editText1 = (EditText)findViewById(R.id.editview1);
-
- //確認按鈕
- Button button = (Button)findViewById(R.id.editbutton0);
-
- button.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View arg0) {
- String username = editText0.getText().toString();
- String password = editText1.getText().toString();
- Toast.makeText(EditTextActivity.this, "用戶名:"+username +"密碼:"+ password, Toast.LENGTH_LONG).show();
- }
- });
- super.onCreate(savedInstanceState);
- }
- }
復制代碼
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <TextView android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textColor="#000000"
- android:textSize="18dip"
- android:background="#00FF00"
- android:text="EditText編輯框測試"
- android:gravity="center_vertical|center_horizontal"
- />
- <EditText
- android:id="@+id/editview0"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:hint="請輸入帳號"
- android:phoneNumber="true"
- />
-
- <EditText
- android:id="@+id/editview1"
- android:layout_width="fill_parent"
-