首先,打开老师给的代码
JAVA程序:
package com.example.tasks;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.Toast;
import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.FindCallback;
import java.util.List;
/**
* Created by ywq on 2016/6/2.
*/
public class AlarmActivity extends Activity {
MediaPlayer alarmMusic;
String note;
String id;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tixing);
id = getIntent().getExtras().getString("id");
// Toast.makeText(this,id,Toast.LENGTH_LONG).show();
final AVQuery<AVObject> query = new AVQuery<>("NoteList");
query.whereEqualTo("objectId", id);
query.findInBackground(new FindCallback<AVObject>() {
@Override
public void done(List<AVObject> list, AVException e) {
for (AVObject avobect : list) {
note = avobect.getString("note");
}
// note = list.get(0).getString("note");
// 加载指定音乐,并为之创建MediaPlayer对象
alarmMusic = MediaPlayer.create(AlarmActivity.this, R.raw.ls3);
alarmMusic.setLooping(true);
// 播放音乐
alarmMusic.start();
// 创建一个对话框
new AlertDialog.Builder(AlarmActivity.this)
.setTitle("提醒")
.setMessage(note)
.setPositiveButton(
"确定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// 停止音乐
alarmMusic.stop();
// 结束该Activity
finish();
}
}
)
.show();
}
});
}
}
activity 程序:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<EditText
android:id="@+id/LoginName"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@android:color/transparent"
android:hint="请输入用户名"
android:inputType="text"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#000000" />
<EditText
android:id="@+id/LoginPwd"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@android:color/transparent"
android:hint="请输入密码"
android:inputType="textPassword"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#000000"/>
<Button
android:id="@+id/Login"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:background="#FFC125"
android:text="登录"
android:textColor="#ffffff"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="没有账号?" />
<TextView
android:id="@+id/Regist1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="马上注册"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
结果: