Hi,
I am new to Android development and have been working on a simple demo
app that needs to update a TextView a few times from an array after a
button is clicked. I have read and adapted the code found here to
achieve this:
http://developer.android.com/resources/articles/timed-ui-updates.html
However, I do not see any updates to my text view - here is my code:
private TextView outputText;
private String[] processes = null;
private Handler updateHandler = new Handler();
private int messageCounter;
private Runnable setMessageTask = new Runnable() {
public void run() {
outputText.setText(processes[messageCounter]);
if (messageCounter < 6) {
messageCounter++;
updateHandler.postAtTime(this, 1000);
}
else {
messageCounter = 5;
}
}
};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b = (Button)findViewById(R.id.askQuestion);
b.setOnClickListener(this);
outputText = (TextView)findViewById(R.id.outputLabel);
messageCounter = 5;
}
public void onClick(View v) {
if (processes == null) {
processes = new String[6];
processes[0] = "msg 1";
processes[1] = "msg 2";
processes[2] = "msg 3";
processes[3] = "msg 4";
processes[4] = "msg 5";
processes[5] = "msg 6";
}
TextView tv = (TextView)findViewById(R.id.outputLabel);
AutoCompleteTextView input =
(AutoCompleteTextView)findViewById(R.id.questionField);
input.setText("");
tv.setText("");
if (messageCounter == 5) {
messageCounter = 0;
updateHandler.removeCallbacks(setMessageTask);
updateHandler.postDelayed(setMessageTask, 1000);
}
}
Can anyone here see what I am doing wrong?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en