Android开发之EditText组件(2)

////////////////strings.xml//////////////////////

<?xml version=https://www.linuxidc.com/Linux/2011-12/"1.0" encoding=https://www.linuxidc.com/Linux/2011-12/"utf-8"?>

<resources>

 

    <string name=https://www.linuxidc.com/Linux/2011-12/"hello">Hello World, ZhuCeActivity!</string>

    <string name=https://www.linuxidc.com/Linux/2011-12/"app_name">ZhuCe</string>

    <string name=https://www.linuxidc.com/Linux/2011-12/"user">用户名:</string>

    <string name=https://www.linuxidc.com/Linux/2011-12/"pass">密码:</string>

    <string name=https://www.linuxidc.com/Linux/2011-12/"twopass">确认密码:</string>

    <string name=https://www.linuxidc.com/Linux/2011-12/"email">电子邮箱:</string>

    <string name=https://www.linuxidc.com/Linux/2011-12/"authcode">验证码:</string>

    <string name=https://www.linuxidc.com/Linux/2011-12/"change">看不清?<a href=https://www.linuxidc.com/Linux/2011-12/"#">换一个</a></string>

    <string name=https://www.linuxidc.com/Linux/2011-12/"text">我已经阅读并同意协议</string>

   

</resources>

自动完成输入内容的组件

package cn.class3g.activity;

import android.app.Activity;

import android.os.Bundle;

import android.widget.ArrayAdapter;

import android.widget.AutoCompleteTextView;

import android.widget.MultiAutoCompleteTextView;

public class AutoActivity extends Activity{

AutoCompleteTextView auto = null;

MultiAutoCompleteTextView mauto = null;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

findViews();

String[] str = {"abc","add","aas","afr","bdr","ber","bsd"};

ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line,str);

auto.setAdapter(adapter);

//----------------------

mauto.setAdapter(adapter);

mauto.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

}

private void findViews(){

auto = (AutoCompleteTextView) this.findViewById(R.id.autoId);

mauto = (MultiAutoCompleteTextView) this.findViewById(R.id.mautoId);

}

}

EditText中回车键的使用

为EditText对象的注册OnKeyListener事件,实现onKey()方法

package cn.class3g.activity;

import android.app.Activity;

import android.os.Bundle;

import android.view.KeyEvent;

import android.view.View;

import android.view.View.OnKeyListener;

import android.widget.Button;

import android.widget.EditText;

public class EditTextTest1Activity extends Activity implements OnKeyListener{

/** Called when the activity is first created. */

Button but = null;

EditText et = null;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.onkey);

findView();

}

public void findView(){

but = (Button) this.findViewById(R.id.buttonId);

et = (EditText) this.findViewById(R.id.edit);

et.setOnKeyListener(this);

}

@Override

public boolean onKey(View v, int keyCode, KeyEvent event) {

// TODO Auto-generated method stub

if(keyCode==KeyEvent.KEYCODE_ENTER){

but.setText(et.getText());

et.setVisibility(View.GONE);

but.setVisibility(View.VISIBLE);

}

return false;

}

}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyfwdf.html