安卓:执行线程与onTouchListener循环() [英] Android: executing the thread in a loop with onTouchListener()
问题描述
你好我的应用程序有8个按键。每个按钮配置onclickListener()被点击的字符串写入TI插座时。现在我想,当我preSS并按住该按钮的字符串必须写在一个循环。这就是我要做的。
Hi in my app there are 8 buttons. Each button is configured onclickListener() when it is clicked the String is written ti the socket. Now i want that when i press and hold the button the String must be written in a loop. Here is what i am trying to do.
bLeft.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent event) {
// TODO Auto-generated method stub
MyThread start = new MyThread();
boolean isReleased = event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL;
boolean isPressed = event.getAction() == MotionEvent.ACTION_DOWN;
while (isPressed) {
start.execute(ip, "left");
break;
}
return false;
}
});
不知何故,我不知道为什么它不工作。开始,执行(字符串,字符串)执行中的AsyncTask类线程创建一个socket输出流。
Somehow i don't know why it is not working. start,execute(string, string) executes the thread in AsyncTask class to create a socket and output stream.
推荐答案
这是asynchronos任务只能执行一次......你试图使用它在一个while循环......这意味着你试图重复使用它。 ..你需要重新初始化启动的,而每次循环......
an asynchronos task can only execute one time... you are trying to employ it in a while loop... meaning you are trying to use it repeatedly... you need to re-initialize start for each iteration of the while loop...
while (ispressed){
start = new YourAsyncTask();
start.execute(params);
}
这篇关于安卓:执行线程与onTouchListener循环()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!