1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Android常见控件— — —EditText

Android常见控件— — —EditText

时间:2021-08-10 07:07:42

相关推荐

Android常见控件— — —EditText

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="/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="/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;

}

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。