0

我想在我的代码中添加一个等待,Button(Enter)被按下的功能,但我还是新手。我知道我的代码中有一些错误我正在玩它,但我想做的是当我按下我希望它显示输入 X、Y、Z 的行时 Button,然后等到按下回车键执行其余的我想添加我的代码。我将如何在我的代码中实现这样的东西?

这是我的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)

    }

}

}

这是我的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];

}

}

4

1 回答 1

0

这就是你所追求的。如果没有道歉!

使用布尔标志来处理应用程序中的状态。这样,如果发生了某些事情,您可以执行不同的代码。

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

    }

}   
于 2013-06-20T05:58:03.520 回答