• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Hi, I have a question about Handler

dakira

Lurker
Hello, I have a question on how to use a Handler.

Here the code in a nut shell

public class A extends Activity {

private Handler handler = new Handler();
private String foobar;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......
Button button = (Button)this.findViewById(R.id.toggleButton);
button.setOnTouchListener(new ButtonHandler());
}

public void updateTextField() {
TextView aView = (TextView)this.findViewById(R.id.textLog);
aView.setText(foobar);
handler.postDelayed(mUpdateUITimerTask, 500);
}

private final Runnable mUpdateUITimerTask = new Runnable() {
public void run() {
// do whatever you want to change here, like:
updateTextField();
}
};


private class ButtonHandler implements OnTouchListener {
public ButtonHandler() {

}

public boolean onTouch(View v, MotionEvent event) {
handler.post(mUpdateUITimerTask);
return true;
}
}
}

When press the button I get
01-13 18:24:40.382: ERROR/AndroidRuntime(337): android.content.res.Resources$NotFoundException: String resource ID #0x0

I wonder if it has something to do that the listener is in an inner class.
Kind of a noob with the environment of Android.

I wrote this code in this editor it wasn't a direct copy and paste. So, there may be compilation errors in wrote I wrote.

Thank you for your suggestions.
dk
 
Lol, never mind. Was trying a setText on a number. I gives a runtime error instead of a compilation error.

Plus, this is not the correct thread for this anyways.
 
Back
Top Bottom