我想發送一個字符串[]到另一個類的內部類中的線程(如果這是有道理的)。 然後,我想用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,然後繪製線。 –