Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timer in expanded list with dynamic button android

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;
                    }
                    ;
                }
            });;
like image 425
Kishor datta gupta Avatar asked Nov 04 '22 05:11

Kishor datta gupta


1 Answers

Just cast View to Button:

@Override
public void onClick(final View v) 
{
   Button btn = (Button) v;
   btn.setText("YourText");
}
like image 136
Dmytro Danylyk Avatar answered Nov 10 '22 03:11

Dmytro Danylyk