Home > Mobile >  Bosses, please help to see where there is a problem...
Bosses, please help to see where there is a problem...

Time:10-09

Package com. Example. (p2);

The import androidx. Appcompat. App. AppCompatActivity;

The import android. OS. Bundle;
The import android. OS. SystemClock;
The import android. View. The view;
The import android. Widget. The Button;
The import android. Widget. Chronometer;
The import android. Widget. TextView;
The import android. Widget. Toast;


Public class MainActivity extends AppCompatActivity implements the View. An OnClickListener, Chronometer. OnChronometerTickListener {

Private Chronometer Chronometer.
Private Button btn_start btn_stop, btn_base btn_format;

@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
The setContentView (R.l ayout. Activity_main);
InitView ();
}

Private void initView () {
Chronometer=(chronometer) the findViewById (R.i, dc hronometer);
Btn_start=(Button) the findViewById (R.i db tnStart);
Btn_stop=(Button) the findViewById (R.i db tnStop);
Btn_base=(Button) the findViewById (R.i db tnReset);
Btn_format=(Button) the findViewById (R.i db tn_format);

Chronometer. SetOnChronometerTickListener (this);
Btn_start. SetOnClickListener (this);
Btn_stop. SetOnClickListener (this);
Btn_base. SetOnClickListener (this);
Btn_format. SetOnClickListener (this);

}

@ Override
Public void onClick (View v) {
The switch (v.g etId ()) {
Case R.i db tnStart:
Chronometer. Start ();//start the time
break;
Case R.i db tnStop:
Chronometer. Stop ();//stop timing
break;
Case R.i db tnReset:
Chronometer. SetBase (SystemClock elapsedRealtime ());//reset
break;
Case R.i db tn_format:
Chronometer. SetFormat (" Time: % s ");//change the time display format
break;
}
}

@ Override
Public void onChronometerTick (Chronometer Chronometer) {
String time=chronometer. GetText (). The toString ();
If (time equals (" prefer ")) {
Toast. MakeText (MainActivity. This, "time is up ~", Toast. LENGTH_SHORT), show ();
}
}

TextView pointTextView;
The Button plusThreePointButton;
The Button plusTwoPointButton;
The Button plusOnePointButton;
The Button resetButton;
The Button plusThreePointButtonTeamb;
The Button plusTwoPointButtonTeamb;
The Button plusOnePointButtonTeamb;


{
PointTextView=the findViewById (R.i d.n umber);
PlusThreePointButton=the findViewById (R.i d.m ain_plus_3point);
PlusTwoPointButton=the findViewById (R.i d.m ain_plus_2point);
PlusOnePointButton=the findViewById (R.i d.m ain_plus_1point);
PlusThreePointButtonTeamb=the findViewById (R.i d.p lus_3point_teamb);
PlusTwoPointButtonTeamb=the findViewById (R.i d.p lus_2point_teamb);
PlusOnePointButtonTeamb=the findViewById (R.i d.p lus_1point_teamb);
ResetButton=the findViewById (R.i d.r eset);


PlusThreePointButton. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View View) {
String currentPoint=pointTextView. GetText (). The toString ();
Int point=Integer. ParseInt (currentPoint);

Point=point + 3;

PointTextView. SetText (String. The valueOf (point));

Toast. MakeText (pointTextView. GetContext (), "Hi," Toast. LENGTH_SHORT), show ();


}
});
ResetButton. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View View) {
String currentPoint=pointTextView. GetText (). The toString ();
Int point=Integer. ParseInt (currentPoint);

Point=0;

PointTextView. SetText (String. The valueOf (point));
}
});
}
}

CodePudding user response:

What problem you meet?

CodePudding user response:

You don't say let you guess? The error message you post out

CodePudding user response:

What's wrong, posted

CodePudding user response:

 
Public void onChronometerTick (Chronometer Chronometer) {
String time=chronometer. GetText (). The toString ();
If (time equals (" prefer ")) {
Toast. MakeText (MainActivity. This, "time is up ~", Toast. LENGTH_SHORT), show ();
}
}

The first place, it is best to the constants in the front, "prefer" actually. Better is to use TextUtils equals to judge,
 
Int point=Integer. ParseInt (currentPoint);

The second place, the Integer parseInt particularly easy to throw a NumberFormatException is unusual, the need to catch,

CodePudding user response:

This is to let you've picked, ha, ha, ha, much upstairs