Android常见控件— — —EditText

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"> <EditText
android:id="@+id/edit_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:hint="请输姓名"
android:maxLines="1"/> <EditText
android:id="@+id/edit_test2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:hint="学号"
android:maxLines="1"/> </LinearLayout>

Android常见控件— — —EditText


应用
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"> <EditText
android:id="@+id/edit_test1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:hint="请输姓名"
android:maxLines="1"/> <EditText
android:id="@+id/edit_test2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:hint="请输入学号"
android:maxLines="1"/> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="确认"
android:layout_gravity="center"
/> </LinearLayout>

Android常见控件— — —EditText


package com.example.uiwidgettest2;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*; public class edittextActivity extends Activity implements View.OnClickListener{ private EditText et1;
private EditText et2;
private Button btn; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edittext);
btn = (Button)findViewById(R.id.button1);
et1 = (EditText)findViewById(R.id.edit_test1);
et2 = (EditText)findViewById(R.id.edit_test2);
btn.setOnClickListener(this);
} @Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button1:
String username = et1.getText().toString();
String id = et2.getText().toString();
Toast.makeText(edittextActivity.this,username+id,Toast.LENGTH_SHORT).show();
break;
default:
break;
}
}
}

Android常见控件— — —EditText

上一篇:Python的Numpy库简述


下一篇:Github上star数超1000的Android列表控件