Android : Handler not working in Android

on Friday, August 15, 2014


I' trying to increment a value in TextView when button was clicked and used Handler as below. Its not incrementing the value of i and displaying only 1 after button was clicked


My activity code is as below



public void changeTxt(View view) {

// invoke handler and call the thread method for every one second

threadHandler.postDelayed(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
i = i + 1;
txtVw.setText(" Number :: " + i);
}
}, 0);

}


Related button layout is



<Button android:id="@+id/buttn"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="Add Value"
android:gravity="center_horizontal"
android:layout_below="@+id/txtView"
android:onClick="changeTxt"

/>

0 comments:

Post a Comment