[英]How to add a wait function till a button is pressed?
I want to add a wait till, Button
(Enter) is pressed function to my code But i am still new to this. 我想等一下,在我的代码中按下Button
(Enter)函数,但是我对此还是很陌生。 I know there are some errors in my code I was playing around with it, But what I want to do is when I press the line Button
I want it to display Input X,Y,Z then wait till enter is pressed to execute the rest of my code I want to add in. How would I implement something like this in my code? 我知道我在处理它的代码中有一些错误,但是我想做的是当我按行 Button
我希望它显示Input X,Y,Z,然后等到按Enter来执行其余操作我要添加的代码中。如何在代码中实现类似的内容?
Here is my MainActivity
Class: 这是我的MainActivity
类:
public class MainActivity extends Activity implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button enter = (Button) findViewById(R.id.enter);
Button line = (Button) findViewById(R.id.line);
Button arc = (Button) findViewById(R.id.arc);
line.setOnClickListener(this);
enter.setOnClickListener(this);
arc.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
TextView vector = (TextView) findViewById(R.id.point);
TextView index = (TextView) findViewById(R.id.index);
TextView info = (TextView) findViewById(R.id.info);
EditText cl = (EditText) findViewById(R.id.editText1);
DrawingUtils call = new DrawingUtils();
switch (v.getId()) {
case R.id.line:
info.setText("Input X,Y,Z");
// This Is Where the Wait Function Will GO
vector.setText(call.addVertice());
index.setText("1");
break;
case R.id.enter:
String In = cl.getText().toString();
call.setInputCoords(In);
break;
case R.id.arc:
info.setText("Enter Vertice1 ");
// Code for entering Vertice1(Also has wait function)
info.setText("Enter Vertice2");
// Code for entering Vertice2(Also has wait function)
info.setText("Enter Height");
//Code for entering Height(Also has wait function)
}
}
} }
Here is my DrawingUtils
Class: 这是我的DrawingUtils
类:
public class DrawingUtils {
String inputCoords;
String[] vertice;
public String getInputCoords() {
return inputCoords;
}
public void setInputCoords(String inputCoords) {
this.inputCoords = inputCoords;
}
public String addVertice() {
int i = 0;
vertice = inputCoords.split(",");
return vertice[i];
}
} }
I think this is what you are after. 我想这就是你所追求的。 Apologies if not! 不好意思!
Use a boolean flag to handle state within your app. 使用布尔值标志处理应用程序内的状态。 This way you can execute different code if something has happened. 这样,如果发生了某些事情,您可以执行不同的代码。
boolean enterPressed = false;
@Override
public void onClick(View v) {
TextView vector = (TextView) findViewById(R.id.point);
TextView index = (TextView) findViewById(R.id.index);
TextView info = (TextView) findViewById(R.id.info);
EditText cl = (EditText) findViewById(R.id.editText1);
DrawingUtils call = new DrawingUtils();
switch (v.getId()) {
case R.id.line:
if (enterPressed) {
vector.setText(call.addVertice());
index.setText("1");
}
else {
info.setText("Input X,Y,Z");
}
break;
case R.id.enter:
String In = cl.getText().toString();
call.setInputCoords(In);
enterPressed = true;
break;
case R.id.arc:
info.setText("Enter Vertice1 ");
// Code for entering Vertice1
info.setText("Enter Vertice2");
// Code for entering Vertice2
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.