diff --git a/soft1614080902117/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity.java b/soft1614080902117/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity.java index a6d0b9132..70af752fc 100644 --- a/soft1614080902117/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity.java +++ b/soft1614080902117/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity.java @@ -1,30 +1,67 @@ package edu.hzuapps.androidlabs.soft1614080902117; + import android.content.Intent; import android.os.Bundle; + import android.view.View; -import android.view.View.OnClickListener; + import android.widget.Button; import android.app.Activity; +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.String; +import android.widget.ArrayAdapter; +import android.widget.ListView; public class Soft1614080902117Activity extends Activity { + String[] adapterData; - Button button = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_soft1614080902117); - - button = (Button)findViewById(R.id.button); - button.setOnClickListener(new OnClickListener() { + final ListView listView = (ListView)findViewById(R.id.listView); + adapterData = new String[] {load()}; + ArrayAdapter arrayAdapter = new ArrayAdapter + ( Soft1614080902117Activity.this, android.R.layout.simple_list_item_1, adapterData); + listView.setAdapter(arrayAdapter); + final Activity thisActivity = this; + Button btnHome = (Button)findViewById(R.id.button); + btnHome.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(); - intent.setClass(Soft1614080902117Activity.this,Soft1614080902117Activity1.class); - startActivity(intent); + Intent intent = new Intent(thisActivity,Soft1614080902117Activity1.class); + thisActivity.startActivity(intent); } }); } + 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(); + } } diff --git a/soft1614080902117/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity1.java b/soft1614080902117/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity1.java index 58ffd5e34..25543ea9d 100644 --- a/soft1614080902117/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity1.java +++ b/soft1614080902117/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity1.java @@ -1,26 +1,67 @@ package edu.hzuapps.androidlabs.soft1614080902117; -import android.content.Intent; + + import android.app.Activity; +import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; -import android.view.View.OnClickListener; +import java.io.BufferedWriter; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.lang.String; +import android.widget.EditText; + + public class Soft1614080902117Activity1 extends Activity { - Button button = null; + private EditText editText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_soft16140809021171); + final Activity thisActivity = this; + Button btnBack = (Button)findViewById(R.id.button3); + Button btnJoin= (Button)findViewById(R.id.button4); + editText = (EditText)findViewById(R.id.editText); - button = (Button)findViewById(R.id.button4); - button.setOnClickListener(new OnClickListener() { + btnBack.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(thisActivity,Soft1614080902117Activity.class); + thisActivity.startActivity(intent); + } + }); + btnJoin.setOnClickListener(new View.OnClickListener() { //添加保存文件 @Override public void onClick(View v) { - Intent intent = new Intent(); - intent.setClass(Soft1614080902117Activity1.this,Soft1614080902117Activity.class); - startActivity(intent); + String inputText = editText.getText().toString(); + save(inputText); + Intent intent = new Intent(thisActivity,Soft1614080902117Activity.class); + thisActivity.startActivity(intent); } }); } -} + + public void save(String inputText){ + FileOutputStream out; + BufferedWriter writer = null; + try { + out = openFileOutput("data", 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(); + } + } + + } +} \ No newline at end of file diff --git a/soft1614080902117/shiyan5.1.png b/soft1614080902117/shiyan5.1.png new file mode 100644 index 000000000..74d691497 Binary files /dev/null and b/soft1614080902117/shiyan5.1.png differ diff --git a/soft1614080902117/shiyan5.2.png b/soft1614080902117/shiyan5.2.png new file mode 100644 index 000000000..8111420b3 Binary files /dev/null and b/soft1614080902117/shiyan5.2.png differ