这次的作业比较简单,就直接简述了
首先是布局


<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/ev_userName" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/ev_userName" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/ev_age" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/ev_password" /> </LinearLayout>
布局很简单,大家都差不多;布局很简单,大家都差不多;布局很简单,大家都差不多
重要的事情说三遍
然后就是Java的编写


protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_share); //获取这些组件findViewId(让其发生关联) evuserName = (EditText) findViewById(R.id.ev_userName); evage = (EditText) findViewById(R.id.ev_age); writer= (Button)findViewById(R.id.writer); //设置按钮(写入)监听事件 writer.setOnClickListener(new View.OnClickListener() {


//设置按钮(读取)监听事件 read = (Button)findViewById(R.id.read); read.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String userName = evuserName.getText().toString(); String filename = "data.txt"; String result = ""; try{ //打开指定文件,并读取其数据 FileInputStream in = openFileInput( filename ); BufferedReader reader = new BufferedReader( new InputStreamReader( in ) ); userName = reader.readLine(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } userName = evuserName.getText().toString(); String age = evage.getText().toString(); Toast.makeText(ShareActivity.this, "输入姓名"+userName+",年龄:" + age,Toast.LENGTH_SHORT).show(); } }); }
不要看了,后面没了