Skip to content

Commit

Permalink
hzuapps#5 惠大考试复习平台
Browse files Browse the repository at this point in the history
  • Loading branch information
aLesion committed Jun 2, 2018
1 parent 78b8741 commit a7b78fa
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.example.soft1614080902114;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.io.FileInputStream;
import java.io.FileOutputStream;

public class Main4Activity extends AppCompatActivity {

private Button seek;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main4);
seek=(Button)findViewById(R.id.button_seek);
seek.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final EditText tx= (EditText) findViewById(R.id.edittext_input);
String s = tx.getText().toString();
if(!s.isEmpty())
save(s);
refresh(s);
}
});
init();
}

public void save(String msg){
if(msg == null) return;
try {
msg += read();
FileOutputStream fos = openFileOutput("storage.txt",
MODE_APPEND);
fos.write(msg.getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}

public String read() {
try {
FileInputStream inStream = this.openFileInput("message.txt");
byte[] buffer = new byte[1024];
int hasRead = 0;
StringBuilder sb = new StringBuilder();
while ((hasRead = inStream.read(buffer)) != -1) {
sb.append(new String(buffer, 0, hasRead));
}
inStream.close();
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

private void refresh(String msg)
{
if(msg==null) return;
TextView textView = (TextView) findViewById(R.id.textview_history);
String s = textView.getText().toString();
textView.setText(s+"\n"+msg);
}

private void init()
{
TextView textView = (TextView) findViewById(R.id.textview_history);
String s = read();
if(s!=null)
refresh(s);
}

}
43 changes: 43 additions & 0 deletions Soft1614080902114/app/src/main/res/layout/activity_main4.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=".Main4Activity">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal">

<EditText
android:id="@+id/edittext_input"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:hint="输入" />
<Button
android:id="@+id/button_seek"
android:layout_width="80dp"
android:layout_height="match_parent"
android:text="查找"
android:layout_gravity="center_horizontal"/>

</LinearLayout>


<TextView
android:id="@+id/textview_history"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="查询历史:"
/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
Binary file added shiyan5.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 a7b78fa

Please sign in to comment.