18乐学成语
来源:互联网 发布:网络视频服务器的作用 编辑:程序博客网 时间:2024/05/16 18:47
strings.xml页面:主页面
[html] view plain copy
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <string name="app_name">happyidiom</string>
- <string name="action_settings">Settings</string>
- <string name="title_study">学习</string>
- <string name="title_search">搜搜</string>
- <string name="title_game">游戏</string>
- <string name="title_save">收藏</string>
- <string name="title_help">帮助</string>
- <string name="animal">动物类</string>
- <string-array name="category">
- <item>动物类</item>
- <item>自然类</item>
- <item>人物类</item>
- <item>季节类</item>
- <item>数字类</item>
- <item>寓言类</item>
- <item>其它类</item>
- </string-array>
- </resources>
在res目录下新建anim文件夹,存放两个动画页面,作为ListView内容显示时的动画效果。
anim_listview.xml页面:
[html] view plain copy
- <?xml version="1.0" encoding="utf-8"?>
- <alpha xmlns:android="http://schemas.android.com/apk/res/android"
- android:duration="1000"
- android:fromAlpha="0.0"
- android:toAlpha="1.0">
- </alpha>
anim_layout_listview.xml页面:
[html] view plain copy
- <?xml version="1.0" encoding="utf-8"?>
- <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
- android:animation="@anim/anim_listview"
- android:animationOrder="random"
- android:delay="0.2">
- </layoutAnimation>
layout文件夹下新建category_item.xml页面,作为显示成语类别ListView的子项目。
category_item.xml页面:
[html] view plain copy
- <?xml version="1.0" encoding="utf-8"?>
- <!-- “学习”中ListView的子布局 -->
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:padding="10dp"
- android:orientation="horizontal" >
- <ImageView
- android:id="@+id/category_image"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/category_animal"/>
- <TextView
- android:id="@+id/category_name"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/animal"
- android:gravity="center"
- android:textColor="#000000"
- android:textAppearance="?android:attr/textAppearanceLarge"/>
- </LinearLayout>
新建animal_item.xml页面,作为显示详细成语ListView的子项目。
animal_item.xml页面:
[html] view plain copy
- <?xml version="1.0" encoding="utf-8"?>
- <!-- 成语列表布局 -->
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:descendantFocusability="blocksDescendants"
- android:padding="10dp" >
- <!-- android:descendantFocusability="blocksDescendants"使ListView中的子控件ImageButton失去焦点 -->
- <TextView
- android:id="@+id/tvName"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:gravity="center"
- android:textColor="#000000"
- android:text="助人为乐"
- android:textAppearance="?android:attr/textAppearanceLarge"/>
- <ImageButton
- android:id="@+id/btnSave"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@null"
- android:layout_alignParentRight="true"
- android:layout_alignTop="@+id/tvName"
- android:src="@drawable/btnsave"/>
- </RelativeLayout>
新建dialog_info.xl页面,用于显示点击成语显示成语解释等信息的对话框页面。
dialog_info.xml页面:
[html] view plain copy
- <!-- 对话框布局 -->
- <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:baselineAligned="@drawable/bg_ling"
- android:orientation="vertical">
- <TextView
- android:id="@+id/tvIdiomInfo"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Medium Text"
- android:textAppearance="?android:attr/textAppearanceMedium"/>
- </LinearLayout>
- </ScrollView>
新建android页面StudyActivity.java页面和activity_study.xml页面,activity_study.xml页面存放成语类别的ListView。
activity_study.xml页面:
[html] view plain copy
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@drawable/bg_ling"
- tools:context=".StudyActivity" >
- <ListView
- android:id="@+id/lvCategories"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:listSelector="#00000000"
- android:layoutAnimation="@anim/anim_layout_listview"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true" >
- </ListView>
- </RelativeLayout>
10.新建android页面StudyAnimalActivity.java页面和activity_animal.xml页面,activity_animal.xml页面存放具体成语的ListView。
activity_anmal.xml页面:
[html] view plain copy
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@drawable/bg_animal"
- android:orientation="vertical" >
- <ListView
- android:id="@+id/lvAnimalList"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layoutAnimation="@anim/anim_layout_listview"
- android:listSelector="#00000000">
- </ListView>
- </LinearLayout>
activity_main.xml页面放置TabHost控件,用于标题的选择。
activity_main.xml页面:
[html] view plain copy
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity" >
- <TabHost
- android:id="@android:id/tabhost"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true" >
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- <TabWidget
- android:id="@android:id/tabs"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
- <FrameLayout
- android:id="@android:id/tabcontent"
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
- <LinearLayout
- android:id="@+id/tab1"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- </LinearLayout>
- <LinearLayout
- android:id="@+id/tab2"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- </LinearLayout>
- <LinearLayout
- android:id="@+id/tab3"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- </LinearLayout>
- </FrameLayout>
- </LinearLayout>
- </TabHost>
- </RelativeLayout>
entity包下新建Category.java类,作为成语类别的实体类。
Category.java页面:
[java] view plain copy
- package cn.edu.bztc.happyidiom.entity;
- public class Category {
- private String name;
- private int imageId;
- public Category(String name, int imageId) {
- super();
- this.name = name;
- this.imageId = imageId;
- }
- public String getName() {
- return name;
- }
- public int getImageId() {
- return imageId;
- }
- }
entity包下新建Animal.java类,作为成语具体信息的实体类。
Animal.java页面:
[java] view plain copy
- package cn.edu.bztc.happyidiom.entity;
- public class Animal {
- private int id;
- private String name;//成语名称
- private String pronounce;//成语发音
- private String explain;//成语解释
- private String antonym;//反义词
- private String homoionym;//同义词
- private String derivation;//源自
- private String examples;//例子
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getPronounce() {
- return pronounce;
- }
- public void setPronounce(String pronounce) {
- this.pronounce = pronounce;
- }
- public String getExplain() {
- return explain;
- }
- public void setExplain(String explain) {
- this.explain = explain;
- }
- public String getAntonym() {
- return antonym;
- }
- public void setAntonym(String antonym) {
- this.antonym = antonym;
- }
- public String getHomoionym() {
- return homoionym;
- }
- public void setHomoionym(String homoionym) {
- this.homoionym = homoionym;
- }
- public String getDerivation() {
- return derivation;
- }
- public void setDerivation(String derivation) {
- this.derivation = derivation;
- }
- public String getExamples() {
- return examples;
- }
- public void setExamples(String examples) {
- this.examples = examples;
- }
- }
db包下新建DBOpenHelper.java页面,用于将复制到raw文件夹下的数据库文件读取并保存到databases文件夹中。
DBOpenHelper.java页面:
[java] view plain copy
- package cn.edu.bztc.happyidiom.db;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import cn.edu.bztc.happyidion.activity.R;
- import android.content.Context;
- import android.database.sqlite.SQLiteDatabase;
- import android.os.Environment;
- import android.util.Log;
- /*实现将数据库文件从raw目录拷贝到手机里存放数据库的位置*/
- public class DBOpenHelper {
- private final int BUFFER_SIZE=400000;//缓冲区大小
- public static final String DB_NAME="idioms.db";//保存的数据库文件名
- public static final String PACKAGE_NAME="cn.edu.bztc.happyidion.activity";//应用的包名
- public static final String DB_PATH="/data"+Environment.getDataDirectory().getAbsolutePath()+"/"+PACKAGE_NAME+"/databases";//在手机里存放数据库的位置
- private Context context;
- public DBOpenHelper(Context context){
- this.context=context;
- }
- public SQLiteDatabase openDatabase(){
- try {
- File myDataPath=new File(DB_PATH);
- if(!myDataPath.exists()){
- myDataPath.mkdirs();//如果没有这个目录则创建
- }
- String dbfile=myDataPath+"/"+DB_NAME;
- if(!(new File(dbfile).exists())){//判断数据库文件是否存在,如果不存在则执行导入,否则直接打开数据库
- InputStream is=context.getResources().openRawResource(R.raw.idioms);
- FileOutputStream fos=new FileOutputStream(dbfile);
- byte[] buffer=new byte[BUFFER_SIZE];
- int count=0;
- while((count=is.read(buffer))>0){
- fos.write(buffer,0,count);
- }
- fos.close();
- is.close();
- }
- SQLiteDatabase db=SQLiteDatabase.openOrCreateDatabase(dbfile,null);
- return db;
- } catch (FileNotFoundException e) {
- Log.e("MainActivity","File not found");
- e.printStackTrace();
- }catch (IOException e) {
- Log.e("MainActivity","IO exception");
- e.printStackTrace();
- }
- return null;
- }
- }
test包下新建DBOpenHelperTest.java页面测试一下数据库是否处理成功。
DBOpenHelperTest.java页面:
[java] view plain copy
- package cn.edu.bztc.happyidiom.test;
- import cn.edu.bztc.happyidiom.db.DBOpenHelper;
- import android.test.AndroidTestCase;
- public class DBOpenHelperTest extends AndroidTestCase{
- public void testDBCopy(){
- DBOpenHelper dbOpenHelper=new DBOpenHelper(getContext());
- dbOpenHelper.openDatabase();
- }
- }
0 0
- 18乐学成语
- 乐学成语
- 乐学成语
- 乐学成语
- 乐学成语2
- 乐学成语
- 乐学成语
- 乐学成语案例
- Android---乐学成语
- 乐学成语
- 乐学成语
- 乐学成语2
- 17乐学成语
- 19乐学成语
- 乐学成语作业
- 乐学成语
- 乐学成语
- 乐学成语
- iOS开发——XML/JSON数据解析
- CentOS安装并设置MariaDB
- Excel Notes
- 手机开发实战188——手机软件开发注意事项2
- IO-缓冲流的使用。
- 18乐学成语
- C++下适合系统自动流程的棋牌游戏服务器桌子类
- 手机开发实战189——手机软件开发注意事项3
- 第十六周程序阅读(3)
- JavaScript基础
- Android开发删除短信(发信箱)
- 手机开发实战190——手机软件开发注意事项4
- Android SQL语句实现数据库的增删改查
- CentOS用yum安装、配置MariaDB