等待T时间推出前的动作? [英] wait t time before launch an action?
问题描述
其实我有一个multiautocompletetextview,在那里我打电话主机后3个字符有一个动态的搜索列表。
但是,如果用户把别人的人物,我的code呼叫主机为他们每个人。所以它必须是很长的。
I actually had a multiautocompletetextview, where i call host after 3 characters to have a dynamic search list. But if the user put others characters, my code call host for each of them. So it must be very long.
开展行动,以看,如果用户做一个动作与否之前,我可以稍等片刻(约500毫秒)?这是可能的?
Could I wait a moment (about 500 ms) before launching the action , in order to look if user do an action or not ? that's possible ?
推荐答案
您可以使用一个线程separeted。当用户输入的文字,你可以创建一个线程,让它睡500毫秒时,如果键入的文本更改会醒过来检查。
You could use a separeted thread. When the user entered the text you could create a thread, make it sleep for 500ms and when it will wake up check if the text typed is changed.
修改
创建一个处理程序
private Handler h = new Handler();
创建一个可运行,使您的动态搜索
Create a runnable that makes your dynamic search
private Runnable myrunnable = new Runnable() {
public void run() {
....
};
然后打电话给你的onTextChanged可运行像
Then call your runnable in onTextChanged like
h.postDelayed(myrunnable, 500);
请参见处理器获得更多选项/信息
请确保您的线程将以一致的方式访问内存!
Make sure that your threads will access the memory in a consistent way!
这篇关于等待T时间推出前的动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!