Exchange 2013sp1邮件系统部署-(二)
2014-09-01 11:08
447 查看
Timer跟TimerTask其实非常简单,用来执行一段规定时间内完成的任务,本文做的是设置Button的文本,首先activity创建的时候会显示默认文本“哈哈”,3S‘之后将Button文本改成“嘿嘿”,如果点击了Button,则定时器会进行新的一轮的定时任务,基于这个原理其实是可以开发类似于轮询的这种业务,但是使用这种方式不太好。
同时,点击Button会切换软键盘的状态,控制显示隐藏软键盘。
如果你想在activity刚创建的时候就调出软键盘,上述切换软键盘状态的函数是不起作用的,要用这个函数,其实没有必要用这段代码显示软键盘,直接在manifest文件里配置activity的时候给activity配置android:windowSoftInputMode="stateVisible|adjustPan"这个属性,就能自动弹出软键盘
同时,点击Button会切换软键盘的状态,控制显示隐藏软键盘。
public class TestTimerTaskActivity extends Activity implements OnClickListener { private static final int MESSAGE_WHAT = 100; private Button btnClick; private Timer mTimer; private TimerTask mTimerTask; private InputMethodManager inputMethodManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.timer); init(); mTimer = new Timer(true); initTimerTask(); } /** * Initialize TimeTask */ private void initTimerTask() { if (null != mTimer && null != mTimerTask) mTimerTask.cancel(); mTimerTask = new MyTimerTask(); mTimer.schedule(mTimerTask, 3000); } /** * Initialize the views */ private void init() { btnClick = (Button) findViewById(R.id.btnClick); btnClick.setOnClickListener(this); inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); } /** * Handler Update UI */ Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (msg.what == MESSAGE_WHAT) { btnClick.setText(String.valueOf(msg.obj)); } } }; /** * Override Button ClickListener */ @Override public void onClick(View v) { int id = v.getId(); switch (id) { case R.id.btnClick: btnClick.setText("哈哈"); initTimerTask(); toggleSoftKeyBoard(); break; default: break; } } /** * toggleSoftKeyBoard status */ private void toggleSoftKeyBoard() { if (inputMethodManager.isActive()) { inputMethodManager.toggleSoftInput( InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); } } /** * Send message to UIThread * * @param what * message identifies * @param str * Content of the message */ private void sendMssage(int what, String str) { Message message = handler.obtainMessage(what, str); handler.sendMessage(message); } /** * Custom Derived class * * @author wallace * */ private class MyTimerTask extends TimerTask { @Override public void run() { sendMssage(MESSAGE_WHAT, "嘿嘿"); } } }
如果你想在activity刚创建的时候就调出软键盘,上述切换软键盘状态的函数是不起作用的,要用这个函数,其实没有必要用这段代码显示软键盘,直接在manifest文件里配置activity的时候给activity配置android:windowSoftInputMode="stateVisible|adjustPan"这个属性,就能自动弹出软键盘
private void toggleSoftKeyBoard() { Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { inputMethodManager.toggleSoftInput( InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); } }, 100); }
相关文章推荐
- Exchange 2013sp1邮件系统部署-(九)
- Exchange 2013sp1邮件系统部署-(四)
- Exchange 2013sp1邮件系统部署-(五)
- Exchange 2013sp1邮件系统部署-(三)
- Exchange 2013sp1邮件系统部署-(六)
- Exchange 2013sp1邮件系统部署-(八)
- Exchange 2013sp1邮件系统部署-(一)
- Exchange 2013sp1邮件系统部署-(七)
- Exchange 2013 SP1部署系列1:系统要求和先决条件安装
- Exchange 2013SP1和O365混合部署系列四
- 微软邮件系统Exchange 2013系列(一)新增功能 推荐
- Exchange 2013SP1和O365混合部署系列二
- Enterprise Vault 10.0.4 FOR Exchange2013 部署之三-日记邮件归档
- 微软邮件系统Exchange 2013系列(十二)从 Exchange 2010 升级至 Exchange 2013-1 推荐
- Exchange 2013SP1和O365混合部署系列五 推荐
- 利用Microsoft Exchange 2003部署企业邮件系统(一)