我想发送一个字符串[]到另一个类的内部类中的线程(如果这是有道理的)。 然后,我想用String []做一些工作,然后将其输出回UI。但我不知道如何做到这一点?我也是如何使用消息,以便我可以控制在UI中将要执行的操作。Android中的处理程序困惑
继承人我MainActivity
:
public class MainActivity extends Activity implements OnClickListener {
EditText cl;
TextView info;
Button enter;
Button line;
Button arc;
Line callLine = new DrawingUtils.Line();
Enter callEnter = new DrawingUtils.Enter();
Arc callArc = new DrawingUtils.Arc();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
info = (TextView) findViewById(R.id.info);
enter = (Button) findViewById(R.id.enter);
line = (Button) findViewById(R.id.line);
arc = (Button) findViewById(R.id.arc);
cl = (EditText) findViewById(R.id.editText1);
Handler uiHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
}
}
};
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.enter:
String in = cl.getText().toString();
String[] Input = in.split(",");
// I would like to send Input[] to the line Thread in DrawingUtils
callEnter.start();
break;
case R.id.line:
callLine.start();
break;
case R.id.arc:
callArc.start();
break;
}
};
}
继承人具有在课堂上与Thread
其他类:
public class DrawingUtils {
// Thread classes for buttons
public static class Line extends Thread {
Thread line = new Thread() {
public void run() {
Looper.prepare();
Handler lineHandler = new Handler() {
public void handleMessage(Message msg) {
// How to get Input from Enter button to use in thread
}
};
Looper.loop();
// Then I need to do some work
// Then Send the worked data back to the uiHandler in
// oncreate().
}
};
}
我使用处理器cuase他们似乎这就是你会为我的代码工作。当有人点击Line时,它会设置一个textview(INPUT POINT1),然后线程将等待,当用户输入x,y,z到edittext并单击Enter时,输入将被放入一个字符串中,然后用逗号分隔并放入转换成一个字符串数组,该数组将处理线程线程,然后在输入代码的末尾调用notifyAll()以允许线程继续并请求下一个输入。在行尾的线程将被处理回UI线程
如果你使用的OpenGL,请告诉我们!我认为AsyncTask可以正常工作,但熟练使用opengl的人可以给你特定的建议! –
是的,生病了会使用opengl输入将是x,y,z坐标例如,当您点击线时,它会要求点1,然后点2,然后绘制线。 –