Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wuhengxin committed May 19, 2018
1 parent 79f1167 commit 303b07a
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.example.john.soft1614080902237;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class M3Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_m3);
final EditText editText=(EditText)findViewById(R.id.edit_text);
//获取控件
Button btnLogin=(Button)findViewById(R.id.chaxun);
Button buttonque=(Button)findViewById(R.id.queding);
//final EditText EdPassword=(EditText) findViewById(R.id.edit_text);
final EditText EdUserName=(EditText)findViewById(R.id.edit_text);

btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences sharedPreferences = getSharedPreferences("jc", Context.MODE_PRIVATE);//创建SharedPreferences对象
SharedPreferences.Editor editor = sharedPreferences.edit(); //需要获取SharedPreferences的编辑对象
editor.putString("username", editText.getText().toString()); //向preferences写入数据:
//editor.putString("Password", EdPassword.getText().toString());
editor.commit();// 向preferences文件中提交数据:
Intent intent=new Intent(M3Activity.this,M5Activity.class);
startActivity(intent);
}
} );
buttonque.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(M3Activity.this,M6Activity.class);
startActivity(intent);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.john.soft1614080902237;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class M5Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_m5);
TextView txtUserName=(TextView) findViewById(R.id.txt_UserName);
// TextView txtPassword=(TextView) findViewById(R.id.txt_Password);

SharedPreferences sharedPreferences = getSharedPreferences("jc", Context.MODE_PRIVATE); //创建SharedPreferences对象
String userName=sharedPreferences.getString("username","");//根据key获取对应的数据
//String password=sharedPreferences.getString("Password","");
// txtPassword.setText(password);//给TextView设置text的值
txtUserName.setText(userName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.john.soft1614080902237;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class M6Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_m6);
}
}
43 changes: 43 additions & 0 deletions Soft1614080902237/app/src/main/res/layout/activity_m3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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=".M3Activity">

<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">


<EditText
android:id="@+id/edit_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10sp"
android:hint="请输入搜索的书名..."
android:maxLength="40"
android:textColorHint="#238745" />

<Button
android:id="@+id/queding"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="确定" />

<Button
android:id="@+id/chaxun"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="查询记录" />
</LinearLayout>

</android.support.constraint.ConstraintLayout>
30 changes: 30 additions & 0 deletions Soft1614080902237/app/src/main/res/layout/activity_m5.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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=".M5Activity">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80sp"
android:layout_marginLeft="30sp"
android:text="搜索记录为:"
android:textSize="40px"/>

<TextView
android:id="@+id/txt_UserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80sp"
android:layout_marginLeft="150sp"
android:textSize="40px"/>

</RelativeLayout>


</android.support.constraint.ConstraintLayout>
9 changes: 9 additions & 0 deletions Soft1614080902237/app/src/main/res/layout/activity_m6.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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=".M6Activity">

</android.support.constraint.ConstraintLayout>

0 comments on commit 303b07a

Please sign in to comment.