当前位置: 首页 > news >正文

诸城市党的建设网站网络舆情监测系统软件

诸城市党的建设网站,网络舆情监测系统软件,wordpress主题授权,百度关键词优化曝光行者seo实训9 数据存储和访问 一、【实训目的】 1、 SharedPreferences存储数据; 2、 借助Java的I/O体系实现文件的存储, 3、使用Android内置的轻量级数据库SQLite存储数据; 二、【实训内容】 1、实现下图所示的界面,实现以下功能: 1&#xff…

实训9  数据存储和访问

一、【实训目的】

1、 SharedPreferences存储数据;

2、 借助Java的I/O体系实现文件的存储,

3、使用Android内置的轻量级数据库SQLite存储数据;

二、【实训内容】

 1、实现下图所示的界面,实现以下功能:

1)用SharedPreferences类,当点击”写入xml文件”按钮, 把“输入你想写入内容”控件中的数据写入到login.xml文件中;

2)用SharedPreferences类,当点击”读取内容”按钮, 把login.xml文件中的数据读到到一个TextView中,并显示内容;

具体步骤:

MainActivity源文件:

package com.example.hahah;import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;public class MainActivity extends Activity {private Button write, read;private EditText writeText, readText;private String fileName = "context.txt";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);write = (Button) findViewById(R.id.btnwritexml);read = (Button) findViewById(R.id.btnreadxml);writeText = (EditText) findViewById(R.id.writecontent);readText = (EditText) findViewById(R.id.readcontent);write.setOnClickListener(new OnClickListener() {public void onClick(View arg0) {write(writeText.getText().toString());}});read.setOnClickListener(new OnClickListener() {public void onClick(View arg0) {readText.setText(read());}});}public String read() {StringBuilder sbBuilder = new StringBuilder("");byte[] buffer = new byte[64];int hasRead;try {FileInputStream fis = openFileInput(fileName);while ((hasRead = fis.read(buffer)) != -1) {sbBuilder.append(new String(buffer, 0, hasRead));}} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return sbBuilder.toString();}public void write(String str) {try {FileOutputStream fos = openFileOutput(fileName, Context.MODE_APPEND);PrintStream ps = new PrintStream(fos);ps.print(str);ps.close();try {fos.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}} catch (FileNotFoundException ex) {ex.printStackTrace();}}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}

Activity_main源代码:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" android:stretchColumns="2"><TableRow><EditTextandroid:id="@+id/writecontent"android:layout_width="0dp"					android:layout_height="wrap_content"android:layout_weight="1.0"				android:hint="输入你想写入的内容" /></TableRow>><TableRow>		<Buttonandroid:id="@+id/btnwritexml"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_column="0"		android:text="写入xml文件" /></TableRow><TableRow><EditTextandroid:id="@+id/readcontent"android:layout_width="0dp"					android:layout_height="wrap_content"/></TableRow>><TableRow>		<Buttonandroid:id="@+id/btnreadxml"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_column="0"		android:text="读取内容" /></TableRow><TableRow>		<Buttonandroid:id="@+id/btnwritetxt"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_column="0"		android:text="写入login.txt文件" /></TableRow><TableRow>		<Buttonandroid:id="@+id/btnwritesql"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_column="0"		android:text="写入数据库" /></TableRow>
</TableLayout>   

运行结果截图:

附注:该专栏是博主上学时的实训项目,可供访客练习与参考。代码质量不是很好,但能实现,仅供参考!  

http://www.hkea.cn/news/622674/

相关文章:

  • 温州建设集团有限公司网站首页百度手机版网页
  • 广西网络干部学院官网seo推广人员
  • 可以做红娘的相亲网站江北seo综合优化外包
  • 公司建设网站需要注意什么软文广告示范
  • 高端网站建设 引擎技企业网页
  • 模仿别人网站百度外链查询工具
  • 教程建设网站广告免费发布信息平台
  • wordpress php5.4支持宁波seo排名优化
  • 宁波制作网站哪个好百度怎么发自己的小广告
  • 新浪网站用什么语言做的百度软件下载
  • wordpress如何做网站重庆seo俱乐部联系方式
  • 教育局两学一做网站深圳全网推广平台
  • 淘宝做详情页代码网站免费大数据查询平台
  • 苹果做安卓游戏下载网站好新媒体营销案例ppt
  • 网络营销实务关键词优化seo优化排名
  • 网站推广优化教程游戏代理加盟平台
  • 网站提升权重全国疫情高峰感染进度
  • 营销型网站怎么做智能建站abc
  • 捷信做单官方网站网络服务主要包括什么
  • 网站建设的方案费用什么时候网络推广
  • 这么做3d展示网站公司百度官网优化
  • 工业设计软件上市公司搜索引擎优化的方法
  • 网站建设公司创意网站网络推广推广
  • 浙江三建建设集团有限公司网站关键词的作用
  • 网站建设官方网站教育培训机构加盟十大排名
  • 万网上传网站seo免费
  • 孝感做网站公司百度热议排名软件
  • 建设网站费用吗廊坊seo快速排名
  • 网站建设公司怎样拓展网站业务大连网站推广
  • 什么网站可以免费做找客户东莞seo建站推广费用