I have a button R1 which is dynamic and create in an expanded list view, i can't create it as public
because it's created at runtime many times, now problem is i want to change the text of the button as timer is running. How i can change button text in timer's run method, because view has no settext method.
R1 = (Button) v.findViewById(R.id.R1);
R1.setOnClickListener(new OnClickListener(){
boolean R1state=true;
TimerTask scanTask;
final Handler handler = new Handler();
Timer t = new Timer();
boolean time=true;
@Override
public void onClick( View v) {
// TODO Auto-generated method stub
scanTask = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
/// here need to change R1 text as timer go }
});
}};
if(!R1state)
{v.getBackground().setColorFilter(Color.GREEN, Mode.ADD);
t.cancel();
v.setEnabled(false);
//R1state=true;
}
else
{ t.schedule(scanTask, 300, 30000);
v.getBackground().setColorFilter(Color.RED, Mode.ADD);
R1state=false;
}
;
}
});;
Just cast View to Button:
@Override
public void onClick(final View v)
{
Button btn = (Button) v;
btn.setText("YourText");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With