FoucusProject 焦点事件
来源:互联网 发布:新品牌网络推广 编辑:程序博客网 时间:2024/05/16 09:17
Mydemo.java
package com.jackie.foucusproject;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
private EditText edit;
private TextView txt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edit=(EditText)findViewById(R.id.edit);
txt=(TextView)findViewById(R.id.txt);
edit.setOnClickListener(new OnClickListenerImpl());
edit.setOnFocusChangeListener(new OnFocusChangeListenerImpl());
}
class OnClickListenerImpl implements OnClickListener{
@Override
public void onClick(View arg0) {
edit.setText("");
}
}
class OnFocusChangeListenerImpl implements OnFocusChangeListener{
@Override
public void onFocusChange(View arg0, boolean hasFocus) {
if(hasFocus){
txt.setText("该组件获得焦点");
}else{
if(edit.getText().length()>0){
txt.setText("该组件失去焦点,且内容合法");
}else{
txt.setText("该组件失去焦点,且输入内容不能为空");
}
}
}}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
private EditText edit;
private TextView txt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edit=(EditText)findViewById(R.id.edit);
txt=(TextView)findViewById(R.id.txt);
edit.setOnClickListener(new OnClickListenerImpl());
edit.setOnFocusChangeListener(new OnFocusChangeListenerImpl());
}
class OnClickListenerImpl implements OnClickListener{
@Override
public void onClick(View arg0) {
edit.setText("");
}
}
class OnFocusChangeListenerImpl implements OnFocusChangeListener{
@Override
public void onFocusChange(View arg0, boolean hasFocus) {
if(hasFocus){
txt.setText("该组件获得焦点");
}else{
if(edit.getText().length()>0){
txt.setText("该组件失去焦点,且内容合法");
}else{
txt.setText("该组件失去焦点,且输入内容不能为空");
}
}
}}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<EditText
android:id="@+id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="请输入查询的内容"/>
<EditText
android:id="@+id/msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="www.ihou.com"/>
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<EditText
android:id="@+id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="请输入查询的内容"/>
<EditText
android:id="@+id/msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="www.ihou.com"/>
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
0 0
- FoucusProject 焦点事件
- 焦点事件
- 焦点事件
- 焦点事件
- 焦点事件
- 焦点事件
- 焦点事件
- 焦点事件
- 事件类型--焦点事件
- 文本框失去焦点事件、获得焦点事件
- 获得焦点事件和失去焦点事件
- 文本框失去焦点事件、获得焦点事件
- 焦点事件的顺序
- 服务端TextBox焦点事件
- 空间焦点事件通知
- JS失去焦点事件
- js 文本框焦点事件
- 什么是焦点事件?
- poj1159
- java io+序列化
- 简明Vim练级攻略
- Roman to Integer
- 批处理命令大全
- FoucusProject 焦点事件
- ubuntu 安装GTK
- 小:英文字母转为小写;微我时物体变小20140718
- 博弈入门小结2
- 去掉android4.0上的状态栏,全屏显示的代码
- 做好当下:要么不去做要么就做到最好!
- Sorting Algorithms Review
- 学习分析cvhaardetectobjects函数
- GUAVA clean code利器