Skip to content

Commit

Permalink
Merge pull request #1689 from Peiweilu/master
Browse files Browse the repository at this point in the history
#4 #219 实验四代码
  • Loading branch information
zengsn authored Apr 28, 2019
2 parents 0d35c6e + 190d67f commit a273beb
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 282 deletions.
4 changes: 2 additions & 2 deletions students/com1709081602330/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Com1709081602330Activity2"></activity>
<activity android:name=".Com1709081602330Activity">
<activity android:name=".Sports_sort"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package edu.hzuapps.androidlabs.com1709081602330;

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

public class MainActivity extends AppCompatActivity {
private Button select_sort;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button select_sort = (Button) findViewById(R.id.select_sort);
select_sort.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent intent = new Intent(MainActivity.this,Sports_sort.class);
startActivity(intent);
}
});
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package edu.hzuapps.androidlabs.com1709081602330;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Sports_sort extends AppCompatActivity {
private Button basketball;
private Button football;
private Button tennis;
private EditText edit_add_sort;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sports_sort);
edit_add_sort = (EditText) findViewById(R.id.edit_add_sort);
String inputText = load();
if (!TextUtils.isEmpty(inputText)) {
edit_add_sort.setText(inputText);
edit_add_sort.setSelection(inputText.length());
Toast.makeText(this, "Restoring succeeded", Toast.LENGTH_SHORT).show();
}
}

//文件存储数据
@Override
protected void onDestroy(){
super.onDestroy();
String inputText = edit_add_sort.getText().toString();
save(inputText);
}
public void save(String inputText){
FileOutputStream out = null;
BufferedWriter writer = null;
try{
out = openFileOutput("data", Context.MODE_PRIVATE);
writer = new BufferedWriter(new OutputStreamWriter(out));
writer.write(inputText);
} catch (IOException e){
e.printStackTrace();
}finally{
try{
if (writer != null){
writer.close();
}
}catch (IOException e){
e.printStackTrace();
}
}
}



//读取数据
public String load(){
FileInputStream in = null;
BufferedReader reader = null;
StringBuilder content = new StringBuilder();

try{
in = openFileInput("data");
reader = new BufferedReader(new InputStreamReader(in));
String line = "";
while ((line = reader.readLine()) != null){
content.append(line);
}
}catch(IOException e){
e.printStackTrace();
}finally {
if (reader != null){
try{
reader.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
return content.toString();
}
}
Binary file not shown.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<TableLayout 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=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="体育比赛直播间"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/select_sort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="选择分类"
/>
<ImageView
android:id="@+id/image_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src = "@drawable/img_1"
/>


</TableLayout>
Loading

0 comments on commit a273beb

Please sign in to comment.