Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed May 20, 2018
1 parent fe5f545 commit 7336839
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
53 changes: 53 additions & 0 deletions soft1614080902442/app/java/soft1614080902442main4Activity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package edu.hzuapps.androidlabs.soft1614080902442;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import android.widget.EditText;
public class soft1614080902442main4Activity extends AppCompatActivity {

String hms;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_soft1614080902442main4);
setTitle("睡眠大师");

}

private void save(String hms) {
SharedPreferences.Editor editor = getSharedPreferences("data", MODE_PRIVATE).edit();//获取对象,并且命名文件的名称
editor.putString("hms", hms); //保存数据
editor.commit();
editor.clear();
Toast.makeText(soft1614080902442main4Activity.this, "保存音乐成功", Toast.LENGTH_LONG).show();
}
private void readPrefs() {
SharedPreferences prefs = getSharedPreferences("data", MODE_PRIVATE); //获取对象,读取data文件
String hms = prefs.getString("hms", ""); //获取文件中的数据
Toast.makeText(soft1614080902442main4Activity.this, "正在播放音乐:"+hms, Toast.LENGTH_LONG).show();
}

public void onClick(View view) { //按钮的点击事件
switch (view.getId()) {
case R.id.xieru:
EditText ethour = (EditText)findViewById(R.id.hour);
hms = ethour.getText().toString();
save(hms); //调用保存方法,将输入的姓名和年龄保存
break;
case R.id.duqu:
readPrefs(); //调用读取方法,将保存的文件中的姓名和年龄显示出来
break;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".soft1614080902442main4Activity">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"


android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"

android:layout_alignParentTop="true"
android:background="#fff">

<EditText
android:id="@+id/naoling"
android:layout_width="match_parent"
android:layout_height="wrap_content"


android:layout_centerVertical="true"
android:hint="搜索助眠音乐" />


<ImageButton
android:id="@+id/查询"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:background="@drawable/search" />

</RelativeLayout>


<EditText
android:id="@+id/hour"
android:layout_width="match_parent"
android:layout_height="wrap_content"


android:layout_centerVertical="true"
android:hint="查找音乐编号" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_marginBottom="170dp"
android:orientation="horizontal">

<Button
android:id="@+id/xieru"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:text="保存该音乐"
android:textSize="20sp" />

<Button
android:id="@+id/duqu"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:text="播放该音乐"
android:textSize="20sp" />


</LinearLayout>


</RelativeLayout>

Binary file added soft1614080902442/实验五图一.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added soft1614080902442/实验五图二.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7336839

Please sign in to comment.