android————EditText
来源:互联网 发布:龙城飞将 知乎 编辑:程序博客网 时间:2024/06/06 03:58
首先关于自动提示的效果
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="AutoCompleteTextView" /> <AutoCompleteTextView android:id="@+id/autotext" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#000" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="MultiAutoCompleteTextView" /> <MultiAutoCompleteTextView android:id="@+id/mul" android:layout_width="fill_parent" android:layout_height="wrap_content" /></LinearLayout>
public class AutoActivity extends Activity {private AutoCompleteTextView auto;private MultiAutoCompleteTextView mult;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.autoeditext);auto=(AutoCompleteTextView) findViewById(R.id.autotext);mult=(MultiAutoCompleteTextView) findViewById(R.id.mul); String[] autoString=new String[]{"张航章","张航11","张航22","张航33","张航涨44",};ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,autoString);auto.setAdapter(adapter);auto.setTextColor(Color.BLACK);mult.setAdapter(adapter);mult.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());//完成对逗号的拆分}}
在编辑框中显示图片的效果
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <EditText android:id="@+id/showimage" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" > </EditText> <Button android:id="@+id/btn_showimage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /></LinearLayout>
public class EditTextImage extends Activity{private EditText editText;private Button button;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.edittextimage);editText=(EditText) findViewById(R.id.showimage);button=(Button) findViewById(R.id.btn_showimage);button.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {try {int i=1+new Random().nextInt(4);Field field=R.drawable.class.getDeclaredField("face"+i); int resourceId=Integer.parseInt(field.get(null).toString()); Bitmap bitmap=BitmapFactory.decodeResource(getResources(), resourceId); ImageSpan imageSpan=new ImageSpan(EditTextImage.this,bitmap); SpannableString spannableString=new SpannableString("face"); spannableString.setSpan(imageSpan, 0, 4,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); editText.append(spannableString);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}});}}
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="使用android:digits属性(数字)" /> <EditText android:layout_width="200dp" android:layout_height="wrap_content" android:layout_margin="10dp" android:digits="0123456789" android:id="@+id/edt_num" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="使用android:digits属性(字母)" /> <EditText android:layout_width="200dp" android:layout_height="wrap_content" android:layout_margin="10dp" android:digits="qwertyuiopasdfghjklmnbvcxz" /> /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="使用android:inputType属性(数字)" /> <EditText android:layout_width="200dp" android:layout_height="wrap_content" android:layout_margin="10dp" android:inputType="number|textCapCharacters" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="使用android:inputType属性(邮箱)" /> <EditText android:layout_width="200dp" android:layout_height="wrap_content" android:layout_margin="10dp" android:inputType="textEmailAddress" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="使用android:mersic属性(浮点)" /> <EditText android:layout_width="200dp" android:layout_height="wrap_content" android:layout_margin="10dp" android:numeric="decimal|signed" /> <Button android:id="@+id/btn_specail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /></LinearLayout>
public class SpecailActivity extends Activity { private Button button;private EditText editText;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.specail);button=(Button) findViewById(R.id.btn_specail);editText=(EditText) findViewById(R.id.edt_num);button.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubString value=editText.getText().toString();if(value==null||value.trim().equals("")){editText.setError("请输入内容");}}});}}
- android API——EditText
- Android手记——Edittext
- Android EditText(一)——EditText的基本使用
- android————EditText
- android学习——EditText的属性
- Android学习备忘016——EditText
- Android开发——EditText属性
- Android笔记——TextView和EditText
- android开发——自定义EditText
- Android中文API——EditText
- Android UI设计——EditText控件
- Android UI 设计——EditText 控件
- Android小技巧——EditText
- Android UI基础——EditText控件
- Android UI设计——EditText控件
- Android学习笔记02——EditText
- Android——EditText-imeOptions属性
- Android EditText 键入事件 —setOnKeyListener
- How to face setbacks
- ProDinner体验
- 装载、链接与库
- 命令行的乱码以及编码的问题的解决方法
- 自己编写行编辑器
- android————EditText
- uva - 123 - Searching Quickly
- sql批量插入数据
- No Pain No Game(hdu4630,树状数组+数学)
- iOS之KVC和KVO
- 逆向输出一个字符串
- 树状数组
- djanglebook
- Pieces(hdu4628,状态压缩的动态规划)