The timer in the extended list with a dynamic push-button android

I have a button R1, which is dynamic and is created in an expanded form of the list, I can’t create it as publicbecause it was created at runtime many times, now the problem is that I want to change the text of the button as the timer is running. How can I change the button text in the timer start method because there is no settext method in the view.

    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;
                    }
                    ;
                }
            });;
+5
source share
1 answer

Just click the View button:

@Override
public void onClick(final View v) 
{
   Button btn = (Button) v;
   btn.setText("YourText");
}
+2
source

All Articles