我知道如何接收数据包,但我希望我的应用程序始终检查收到的数据包
public void controlListener(){
control.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(receiveData().charAt(0)){
case '1':{
Log.d("","1");
setVisibility(View.INVISIBLE);
control.setVisibility(View.VISIBLE);
break;
}
case '3':{
Log.d("","3");
setVisibility(View.VISIBLE);
control.setVisibility(View.INVISIBLE);
Thread thread = new Thread()
{
@Override
public void run() {
try {
Log.d("", "here");
runOnUiThread(new Runnable() {
public void run() {
switch(receiveData().charAt(0)){
case '1':{
Log.d("", "1");
setVisibility(View.INVISIBLE);
control.setVisibility(View.VISIBLE);
break;
}
case '3':{
Log.d("", "3");
setVisibility(View.VISIBLE);
control.setVisibility(View.INVISIBLE);
break;
}
case '4':{
Log.d("", "4");
setVisibility(View.INVISIBLE);
control.setVisibility(View.VISIBLE);
break;
}
default:{
Log.d("","not expecting this");
}
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
};
thread.start();
break;
}
case '4':{
Log.d("","4");
setVisibility(View.INVISIBLE);
control.setVisibility(View.VISIBLE);
break;
}
default:{
Log.d("","not expecting this");
}
}
}
});
}
我收到 3 后我想做的事情也继续接收,直到我收到 1 或 4。并允许用户在它为 3 时使用按钮。如果 1 或 4 使所有按钮在收到之前不可见一个 3。