Android - 按下按钮控制循环流程

时间:2013-05-10 08:22:19

标签: android

我的Android App中有一个活动类,在处理完一些数据之后,该数据被发送到另一个类中的另一个方法,该类返回一个ArrayList。我想要做的是遍历ArrayList,并为其中的每一段文本,我想更新我的界面中的TextView标签。但是,只要用户按下屏幕上的“是”按钮,就应该这样做。 (即,每当用户按下“是”按钮时,循环将前进到ArrayList的下一个元素,并且其值在TextView标签中更新)。以下是我到目前为止的情况:

try {
        sentenceGenerator = new SentenceGenerator();
        ArrayList<ArrayList<String>> states = stateGenerator
                .getPossibleStates(resultOutput, result, result);
        for (ArrayList<String> state : states) {
            viewPoint = state.get(0);
            subject = state.get(1);
            object = state.get(2);
            subjectInfo = new ObjectReference();
            if (resultOutput.equals("Sliema")) {
                Sliema sliema = new Sliema();
                subjectInfo = sliema.getInfo(viewPoint, object, subject);
            }
            try {
                s = sentenceGenerator.generateSentence("start", "middle",
                        "end", resultOutput, viewPoint, object, subject,
                        subjectInfo.type, subjectInfo.name,
                        subjectInfo.properties, false);
                instructionTextView = (TextView) findViewById(R.id.instructionTextView);
                mHandler = new Handler();
                instructionTextView
                        .setText("Press 'Yes' to start Orientation procedure");
                Button confirmButton = (Button) findViewById(R.id.confirmButton);
                Button declineButton = (Button) findViewById(R.id.declineButton);

                confirmButton
                        .setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                mHandler.post(mUpdate);
                            }
                        });
                declineButton
                        .setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                //
                            }
                        });
                Log.d("INSTRUCTIONS", s);
            } catch (Exception e) {
            }
        }
    } catch (ClassNotFoundException e) {
    }

这是更新处理程序:

private Runnable mUpdate = new Runnable() {
    public void run() {

        instructionTextView.setText(s);
        // mHandler.postDelayed(this, 1000);
        confirmPressed = true;
        // i++;
    }
};

有什么建议吗?提前谢谢!

1 个答案:

答案 0 :(得分:0)

尝试在要终止循环的break;中添加buttonclickListener