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

网站建设进度说明爱站查询工具

网站建设进度说明,爱站查询工具,猪八戒兼职网,网站建设用cms该实例是用户将自己不熟悉的单词添加到数据库中,当用户需要查询某个单词或是解释时,在相应的文本框中输入相应的关键词,就会出来相应的结果。 本实例主要是用来学习,只是实现了简单的添加和模糊查询,提供一条思路。&a…

该实例是用户将自己不熟悉的单词添加到数据库中,当用户需要查询某个单词或是解释时,在相应的文本框中输入相应的关键词,就会出来相应的结果。

本实例主要是用来学习,只是实现了简单的添加和模糊查询,提供一条思路。(很多Bolg上都有类似的例子,如有雷同,纯属巧合吐舌头

上代码:

1. 布局文件的主界面:dict_sqlite.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <EditText android:id="@+id/word" android:layout_width="fill_parent" android:layout_height="wrap_content" android:focusable="true" android:hint="生词" /> <EditText android:id="@+id/detail" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="生词解释" /> <Button android:id="@+id/insert" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="添加生词" /> <EditText android:id="@+id/key" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Button android:id="@+id/search" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="查找 " /> </LinearLayout>


2.查询结果的ListView的布局文件:popup.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ListView android:id="@+id/show_dict" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout>


3. 查询结果中ListView中适配器的布局文件:line.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/textView_Result_Dict" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="找到的单词" /> <EditText android:id="@+id/word_result_dict" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="解释" /> <EditText android:id="@+id/detail_result_dict" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>

4. 主程序的代码:

(1.) 自定义的SQLiteOpenHelper的子类来管理数据库的连接:MyDatabaseHelper.java:

package com.infy.configuration; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteDatabase.CursorFactory; public class MyDatabaseHelper extends SQLiteOpenHelper{ final String CREATE_TABLE_SQL="create table dict(_id integer primary key autoincrement,word,detail)"; public MyDatabaseHelper(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version); // TODO Auto-generated constructor stub } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub //第一个使用数据库时自动建表 db.execSQL(CREATE_TABLE_SQL); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub } }

(2.) 主界面的代码:Dict.java:

package com.infy.configuration; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class Dict extends Activity{ MyDatabaseHelper dbHelper; Button insert= null; Button search = null; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.dict_sqlite); //创建MyDatabaseHelper对象,指定数据库版本为1,此处使用相对路径即可数据库文件会自动保存在程序的数据文件夹的database目录下 dbHelper = new MyDatabaseHelper(this, "my_Dict.db3", null, 1); insert = (Button)findViewById(R.id.insert); search = (Button)findViewById(R.id.search); final EditText word = (EditText)findViewById(R.id.word); final EditText detail =(EditText)findViewById(R.id.detail); final EditText key=(EditText)findViewById(R.id.key); //插入生词的操作 insert.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //获取用户的输入 String word_user= word.getText().toString(); String detail_word=detail.getText().toString(); //插入生词记录 insertData(dbHelper.getReadableDatabase(),word_user,detail_word); //提示信息 Toast.makeText(Dict.this, "添加生词成功!", Toast.LENGTH_LONG).show(); } }); //收索生词的记录 search.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //获取用户的输入 String key_user = key.getText().toString(); //执行查询操作 Cursor cursor = dbHelper.getReadableDatabase().rawQuery("select *from dict where word like ? or detail like ?", new String[]{ "%" +key_user +"%" ,"%" +key +"%"}); //创建一个Bundle对象 Bundle data = new Bundle(); data.putSerializable("data", converCursorToList(cursor)); //创建一个Intent Intent intent = new Intent(Dict.this,ResultActivity.class); intent.putExtras(data); startActivity(intent); } }); } //把cursor转化成list protected ArrayList<Map<String, String> > converCursorToList(Cursor cursor){ ArrayList<Map<String, String>> result = new ArrayList<Map<String,String>>(); //遍历Cursor结果集 while(cursor.moveToNext()){ //将结果集集中地数据存入Arraylist中 Map<String,String> map = new HashMap<String, String>(); map.put("word", cursor.getString(1)); map.put("detail", cursor.getString(2)); result.add(map); } return result; } private void insertData(SQLiteDatabase db,String word,String detail){ //执行插入语句 db.execSQL("insert into dict values(null,?,?)",new String[]{word,detail}); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); //退出程序时关闭MyDatabaseHelper里的SQLiterDatabse if(dbHelper != null){ dbHelper.close(); } } }


(3.)查询结果的代码:ResultActivity.java

package com.infy.configuration; import java.util.List; import java.util.Map; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.ListView; import android.widget.SimpleAdapter; public class ResultActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.popup); ListView listView = (ListView)findViewById(R.id.show_dict); Intent intent = getIntent(); //获取该Intent中的数据 Bundle data = intent.getExtras(); //从Bundle数据包中获取数据 @SuppressWarnings("unchecked") List<Map<String, String>> list = (List<Map<String,String>>)data.getSerializable("data"); //将List封装成SimpleAdapter SimpleAdapter adapter = new SimpleAdapter(ResultActivity.this,list,R.layout.line,new String[]{"word","detail"},new int[]{R.id.word_result_dict,R.id.detail_result_dict}); //填充ListView listView.setAdapter(adapter); } }


上面的ResultActivity设为了对话框风格的Activitiy.以对话框的方式来显示查询结果。

清单文件AndroidManifest.xml为:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.infy.configuration" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".Dict" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".ResultActivity" android:theme="@android:style/Theme.Dialog"/> </application> <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name ="android.permission.INTERENT"/> </manifest>


结果图:

(1.)添加生词的界面:

(2.))查询结果的界面:在查找按钮上面的文本框中输入P字母,点击查找按钮将出现如下查询结果的界面:

http://www.lbrq.cn/news/2520091.html

相关文章:

  • 建立个人博客网站搜索引擎优化的例子
  • 车公庙做网站盘古搜索
  • 北京市人大网站建设杭州seo营销
  • 小语种网站怎么做曼联vs恩波利比分
  • 个人简介网站html代码网店运营与管理
  • 如何建设网站与域名长沙seo优化首选
  • 网站开发 视频存在哪合肥百度推广优化排名
  • 网站建设中的英文百度快速排名点击器
  • 商业网站建设案例全球搜钻是什么公司
  • wordpress新用户网站优化培训
  • wordpress 数据库名称域名查询seo
  • 济南网站建设企业网页设计html代码大全
  • 长春网站建设致电吉网传媒优上海网站排名优化怎么做
  • 手机网站模板html5网站为什么要seo?
  • 辅助购卡网站怎么做百度推广怎么使用教程
  • 软装设计培训班哪家好seo专员是什么职位
  • b2b是什么意思啊百科成都关键词seo推广平台
  • 云服务器建设网站qq群引流推广平台
  • 电商小程序开发平台小学生班级优化大师
  • 比较好的平面设计网站新闻发稿
  • 网站的建设项目是什么意思semi认证
  • 6.网站开发流程是什么酒吧营销用什么软件找客源
  • 阿里云网站建设一次付费百度竞价客服
  • 哪些做园林的网站人民日报客户端
  • 网站首页面房地产销售怎么找客户
  • 商城网站管理系统上海互联网公司排名
  • 网站开发导航开一个免费网站
  • 怎样使用自己的电脑做网站选择宁波seo优化公司
  • 做网站需要哪些技术人员收录提交入口网址
  • 网站整站必应搜索引擎怎么样
  • 数据库中使用SQL作分组处理01(简单分组)
  • 通达OA服务器无公网IP网络,如何通过内网穿透实现外网远程办公访问OA系统
  • Shopify Draggable + Vue 3 完整指南:打造现代化拖拽交互体验
  • 疯狂星期四文案网第24天运营日记
  • leaflet中绘制轨迹线的大量轨迹点,解决大量 marker 绑定 tooltip 同时显示导致的性能问题
  • C++ AI流处理核心算法实战