0

I want Chronometer to display my timer. When Chronometer.stop is called, i want to stop timer and display text at same place.

Timer is getting stopped but after stopping when i try to

setText("Stopped");  

It is not working. Please let me know if i'm doing valid things or not.

XML changes:

     <Chronometer android:id="@+id/timer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/green"
        android:visibility="visible" />

Code changes:

        mTimer = (Chronometer) mRootGroupView.findViewById(R.id.timer);

On two buttons i'm starting and stopping timer.

      mTimer.stop();
      mTimer.setText("stopped"); 
      mTimer.setVisibility(View.VISIBLE);
      mTimer.setTextColor(color.red);

Please HELP !!!

parul
  • 363
  • 1
  • 6
  • 16

1 Answers1

1

Solution:

Problem was at setting color, thats why it wasnt displaying text at all (as if text is set to invisible)

modified code to :

      //mTimer.setTextColor(color.red);
      mTimer.setTextColor(getResources().getColor(R.color.red));

It started working, I donno why it was giving problem. red color is defined in res/values/colors.xml.

parul
  • 363
  • 1
  • 6
  • 16
  • I had similar problem - chronometer showed text only when touched where I supposed it could be drawn. Setting it any color solved the problem. – Petr Marek Feb 16 '15 at 16:15