我的Android應用程序中有一個活動類,在處理完一些數據之後,將數據發送到另一個返回ArrayList的類中的另一個方法。我想要做的是迭代通過該ArrayList和其中的每一個文本,我想更新我的界面中的TextView標籤。然而,只要用戶按下屏幕上的「是」按鈕,就應該這樣做。 (即無論何時用戶按下'是'按鈕,循環將前進到ArrayList的下一個元素,並在TextView標籤中更新其值。以下是我迄今爲止:Android - 通過按鈕控制循環的流程
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++;
}
};
有什麼建議?提前致謝!
[求助] - 我採取了另一種方法,它的工作。我在那裏天真地思考了一會兒! – k0rtin 2013-05-10 10:34:24