码迷,mamicode.com
首页 > 移动开发 > 详细

Android常见控件— — —EditText

时间:2016-02-29 16:17:37      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

<?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>

技术分享

 


 

应用
<?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>

技术分享


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

标签:

原文地址:http://www.cnblogs.com/xkck/p/5227408.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!