0
這是代碼是在TextView的顯示消息無法顯示的消息中的TextView報警管理器
Button can1 = (Button) findViewById(R.id.can1);
txt1 = (TextView) findViewById(R.id.txt1);
Calendar c = Calendar.getInstance();
hr1 = c.get(Calendar.HOUR_OF_DAY);
startAlarm();
if(hr1<12)
{
txt1.setText("Good morning!");
}else if(hr1>12&& hr1<17)
{
txt1.setText("it's afternoon!");
}else if(hr1>17&& hr1<20)
{
txt1.setText("Good evening!");
}
can1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
private void startAlarm() {
if (alarm.getAlarmTonePath() != "") {
mediaPlayer = new MediaPlayer();
if (alarm.getVibrate()) {
vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
long[] pattern = { 1000, 200, 200, 200 };
vibrator.vibrate(pattern, 0);
}
try {
mediaPlayer.setVolume(1.0f, 1.0f);
mediaPlayer.setDataSource(this,
Uri.parse(alarm.getAlarmTonePath()));
mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
mediaPlayer.setLooping(true);
mediaPlayer.prepare();
mediaPlayer.start();
}
}
}
我的用於顯示信息和按鈕佈局是
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="50dp"/>
<Button
android:id="@+id/can1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:tag="cancel" />
</LinearLayout>
請建議我什麼是錯的代碼, 我能夠顯示取消按鈕但文本(消息)不顯示
什麼是hr1?什麼價值? –
您的hrs1數據內容可能會出現在其他部分,因此請檢查它。 – prakash
hr1是當天的當前小時 – Anwesh