项目乐学成语HappyIdiom

      在做这个项目之前,我们首先要创建数据库。数据库创建好了后便要开始编码了。首先需要在项目下创建存放所有活动相关代码的activity包,用于存放所有数据库相关代码的db包,用于存放所有实体的代码的entity包,用于存放数据操作相关的代码的dao包,用于存放所有工具相关的util包,还有test包,adapter包

代码如下:

db包中的DBOpenHelper类

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.happyidiom.R;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;
import android.util.Log;

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.happyidiom";//应用的包名
       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("Database","File not found");
    		   e.printStackTrace();
    	   }catch(IOException e){
    		   Log.e("Database","IO exception");
    		   e.printStackTrace();
    	   }
    	   return null;
       }

}
然后搭建单元测试环境,修改AndroidManifest.xml文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="cn.edu.bztc.happyidiom"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar" >
        <uses-library android:name="android.test.runner" />

        <activity
            android:name="cn.edu.bztc.happyidiom.activity.MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="cn.edu.bztc.happyidiom.activity.StudyActivity"
            android:label="@string/title_activity_study" >
        </activity>
        <activity android:name="cn.edu.bztc.happyidiom.activity.StudyAnimalActivity">
        </activity>
    </application>

    <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="cn.edu.bztc.happyidiom" >
    </instrumentation>

</manifest>
在test包下新建DBOpenHelperTest类<pre name="code" class="java">//只封装了一个方法,该方法调用了DBOpenHelper类里面定义的openDatabase()方法
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();
	}

}

 然后在entity包下新建Animal类 
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;
	}
	
     
}
然后在dao包中新建AnimalDao类
package cn.edu.bztc.happyidiom.dao;

import java.util.ArrayList;
import java.util.List;

import cn.edu.bztc.happyidiom.db.DBOpenHelper;
import cn.edu.bztc.happyidiom.entity.Animal;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class AnimalDao {
  private static AnimalDao animalDao;
  private SQLiteDatabase db;
  /**
   * 将构造方法私有化
   */
  private AnimalDao(Context context){
	  DBOpenHelper dbHelper = new DBOpenHelper(context);
	  db=dbHelper.openDatabase();
  }
  /**
   * 获取AnimalDao的实例。
   */
  public synchronized static AnimalDao getInstance(Context context){
	  if(animalDao==null){
		  animalDao = new AnimalDao(context);
	  }
	return animalDao;
	  }
  /**
   * 从数据库读取所有的动物类成语。
   */
  public List<Animal> getAllAnimals(){
	  List <Animal> list=new ArrayList<Animal>();
	  Cursor cursor = db.query("animal",null,null,null,null,null,null);
	  if(cursor.moveToFirst()){
		  do{
			  Animal animal = new Animal();
			  animal.setId(cursor.getInt(cursor.getColumnIndex("_id")));
			  animal.setName(cursor.getString(cursor.getColumnIndex("name")));
			  animal.setPronounce(cursor.getString(cursor.getColumnIndex("pronounce")));
			  animal.setExplain(cursor.getString(cursor.getColumnIndex("explain")));
			  animal.setAntonym(cursor.getString(cursor.getColumnIndex("antonym")));
			  animal.setHomoionym(cursor.getString(cursor.getColumnIndex("homoionym")));
			  animal.setDerivation(cursor.getString(cursor.getColumnIndex("derivation")));
			  animal.setExamples(cursor.getString(cursor.getColumnIndex("examples")));
			  list.add(animal);
		  }while(cursor.moveToNext());
	  }
	return list;
	}
}
在Test包下创建AnimalDaoTest类
package cn.edu.bztc.happyidiom.test;

import java.util.List;

import cn.edu.bztc.happyidiom.dao.AnimalDao;
import cn.edu.bztc.happyidiom.entity.Animal;
import android.test.AndroidTestCase;

public class AnimalDaoTest extends AndroidTestCase {
   public void testGetAllAnimals(){
	   AnimalDao animalDao=AnimalDao.getInstance(getContext());
	   List <Animal> animals = animalDao.getAllAnimals();
	   System.out.println(animals.size());
	   for(Animal animal:animals){
		   System.out.println(animal.getName());
	   }
   }
}
然后需要我们完成主页面的设计,在res的drawable-hdpi目录下拷入需要的图片素材,然后在res/layout新建activity_main.xml
<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@android:style/Theme.NoTitleBar"
    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"> 
       </TabWidget>     
       <FrameLayout 
           android:id="@android:id/tabcontent"
           android:layout_width="match_parent"
           android:layout_height="match_parent">
           <LinearLayout 
               android:id="@+id/tab1"
               android:orientation="vertical"
               android:layout_width="match_parent"
               android:layout_height="match_parent">
              </LinearLayout>
            <LinearLayout  
               android:id="@+id/tab2"
               android:orientation="vertical"
               android:layout_width="match_parent"
               android:layout_height="match_parent">
               </LinearLayout>   
             <LinearLayout  
               android:id="@+id/tab3"
               android:orientation="vertical"
               android:layout_width="match_parent"
               android:layout_height="match_parent">
               </LinearLayout>   
             </FrameLayout>
            </LinearLayout>
           </TabHost>
</RelativeLayout>
再在res的values下的string.xml定义所需字符
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">HappyIdiom</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
    <string name="title_activity_main">MainActivity</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-array name="category">
        <item>动物类</item>
        <item>自然类</item>
        <item>人物类</item>
        <item>季节类</item>
        <item>数字类</item>
        <item>寓言类</item>
        <item>其他类</item>
    </string-array>

    <string name="title_activity_study">StudyActivity</string>

</resources>
然后在activity包下新建MainActivity类
/*
 * 这个类中的onCreate()方法,通过调用getTabHost()方法来获取整个TabHost组件。
 * 然后调用抽取出来的自定义方法addTab()添加了五个选项卡
 */
package cn.edu.bztc.happyidiom.activity;
import cn.edu.bztc.happyidiom.R;
import android.os.Bundle;

import android.app.TabActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.Window;
import android.widget.TabHost;

@SuppressWarnings("deprecation")
public class MainActivity extends TabActivity {
    private TabHost tabHost;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);//取消标题栏
		setContentView(R.layout.activity_main);
		tabHost = getTabHost();
		addTab("study",R.string.title_study,R.drawable.search,StudyActivity.class);
	    addTab("search",R.string.title_search,R.drawable.search,StudyActivity.class);
	    addTab("game",R.string.title_game,R.drawable.game,StudyActivity.class);
	    addTab("save",R.string.title_save,R.drawable.save,StudyActivity.class);
	    addTab("help",R.string.title_help,R.drawable.search,StudyActivity.class);
	}

	private void addTab(String tag, int title_introduction, int title_icon,  Class ActivityClass){
		// TODO Auto-generated method stub
		tabHost.addTab(tabHost.newTabSpec(tag).setIndicator(getString(title_introduction),
				     getResources().getDrawable(title_icon)).setContent(new Intent(this,ActivityClass)));
	}

	@Override
	public 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;
	}

}
然后在entivity包下新建类Category
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;
    	
    }
}
在layout下新建activity_study.xml文件
<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    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>
然后接着新建category_item.xml文件
<?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: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="animal"
       android:gravity="center"
       android:textAppearance="?android:attr/textAppearanceLarge"/>
</LinearLayout>
然后在adapter包下新建类CategoryAdapter
package cn.edu.bztc.happyidiom.adapter;

import java.util.List;

import cn.edu.bztc.happyidiom.entity.Category;
import cn.edu.bztc.happyidiom.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CategoryAdapter extends ArrayAdapter<Category>{
   private int resourceld;
	public CategoryAdapter(Context context, int resource,
			List<Category> objects) {
		super(context, resource, objects);
		// TODO Auto-generated constructor stub
      resourceld=resource;
	}
   /*
    * 我们可以在getView()中进行判断,如果convertView为空,则使用LayoutInflater
    * 去加载布局,如果不为空则直接对convertView进行重用。
    */
	public View getView(int position,View convertView,ViewGroup parent){
		Category category=getItem(position);//获取当前项的Category实例
	    View view;
	    ViewHolder viewHolder;
	    if(convertView==null){
	    	view = LayoutInflater.from(getContext()).inflate(resourceld,null);
	    	viewHolder = new ViewHolder();
	    	viewHolder.categoryImage=(ImageView)view.findViewById(R.id.category_image);
	        viewHolder.categoryName=(TextView)view.findViewById(R.id.category_name);
	        view.setTag(viewHolder);
	    }else{
	    	view=convertView;
	    	viewHolder=(ViewHolder)view.getTag();//重新获取ViewHolder
	    	
	    }
	    viewHolder.categoryImage.setImageResource(category.getImageId());
    	viewHolder.categoryName.setText(category.getName());
    	return view;
	}
	       class ViewHolder{
	    	   ImageView categoryImage;
	    	   TextView categoryName;
	       }
		/*ImageView categoryImage=(ImageView)view.findViewById(R.id.category_image);
		TextView categoryName=(TextView)view.findViewById(R.id.category_name);
		categoryImage.setImageResource(category.getImageId());
		categoryName.setText(category.getName());
		return view;*/
	}
在activity包下新建StudyActivity类
package cn.edu.bztc.happyidiom.activity;

import java.util.ArrayList;
import java.util.List;

import cn.edu.bztc.happyidiom.adapter.CategoryAdapter;
import cn.edu.bztc.happyidiom.entity.Category;
import cn.edu.bztc.happyidiom.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class StudyActivity extends Activity {
     private List<Category>categoryList;
     private String[] category_names;
     private int[] category_images;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_study);
		initCategories();//初始化类别
		CategoryAdapter adapter=new CategoryAdapter(this,R.layout.category_item,categoryList);
	    ListView listView=(ListView) findViewById(R.id.lvCategories);
	    listView.setAdapter(adapter);
	    listView.setOnItemClickListener(new OnItemClickListener(){
	    	@Override
			public void onItemClick(AdapterView<?> adapterView, View view, int position,
					long id) {
				// TODO Auto-generated method stub
	    		switch(position){
	    		case 0:
	    			Intent intent=new Intent(StudyActivity.this,StudyAnimalActivity.class);
	    		    startActivity(intent);
	    		 break;
	    		 default:
	    			  break;
	    		}
				//Category category=categoryList.get(position);
				//Toast.makeText(StudyActivity.this, category.getName(), Toast.LENGTH_LONG).show();
			}
	    });
	}

	private void initCategories() {
		// TODO Auto-generated method stub
		categoryList=new ArrayList<Category>();
		Resources resources = getResources();
		category_names=resources.getStringArray(R.array.category);
		category_images=new int[]{R.drawable.category_animal,
				R.drawable.category_nature,R.drawable.category_human,
				R.drawable.category_season,R.drawable.category_number,
				R.drawable.category_fable,R.drawable.category_other};
		for(int i=0;i<category_names.length;i++){
			categoryList.add(new Category(category_names[i],category_images[i]));
		}
	}
/*
 * 这里添加了一个initCategories()方法,用于初始化所有的类别数据。并且在onCreate()方法中创建了CategoryAdapter对象,
 * 把CategoryAdapter作为适配器传递给了ListView。
 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.study, menu);
		return true;
	}

}
然后在res目录下创建anim目录,创建anim_listview.xml文件
<?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文件
<?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下新建activity_animal.xml文件
<?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>
再新建animal_itwm.xml文件
<?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:padding="10dp">
    <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: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>
然后再在adapter包下创建类AnimalAdapter
package cn.edu.bztc.happyidiom.adapter;

import java.util.List;

import cn.edu.bztc.happyidiom.entity.Animal;
import cn.edu.bztc.happyidiom.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class AnimalAdapter extends ArrayAdapter<Animal>{
    private int resourceld;
    private Context context;
	public AnimalAdapter(Context context, int resource,List<Animal>objects) {
		super(context, resource,objects);
		this.context=context;
	    resourceld = resource;
		// TODO Auto-generated constructor stub
	}
     public View getView(int position,View convertView,ViewGroup parent){
		final Animal animal=getItem(position);//获取当前项的Animal实例
		View view;
		ViewHolder  viewHolder;
		if(convertView ==null){
			view=LayoutInflater.from(getContext()).inflate(resourceld, null);
            viewHolder=new ViewHolder();
            viewHolder.tvName=(TextView)view.findViewById(R.id.tvName);
            viewHolder.btnSave=(ImageButton)view.findViewById(R.id.btnSave);
            viewHolder.btnSave.setFocusable(false);
            viewHolder.btnSave.setFocusableInTouchMode(false);
            viewHolder.btnSave.setOnClickListener(new OnClickListener(){
            	public void onClick(View view){
            		Toast.makeText(context, "你要收藏"+animal.getName()+"吗",Toast.LENGTH_SHORT ).show();
            	}
            });
		    view.setTag(viewHolder);
		}else{
			view=convertView;
			viewHolder=(ViewHolder)view.getTag();
		}
		viewHolder.tvName.setText(animal.getName());
		
    	 return view;
    	 
     }
     class ViewHolder{
    	 TextView tvName;
    	 ImageButton btnSave;
     }
}
在activity下新建StudyAnimalActivity
package cn.edu.bztc.happyidiom.activity;

import java.util.List;

import cn.edu.bztc.happyidiom.adapter.AnimalAdapter;
import cn.edu.bztc.happyidiom.dao.AnimalDao;
import cn.edu.bztc.happyidiom.entity.Animal;
import cn.edu.bztc.happyidiom.util.DialogUtil;
import cn.edu.bztc.happyidiom.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class StudyAnimalActivity extends Activity{
    private List<Animal>animalList;
    private AnimalDao animalDao;
    private ListView lvAnimalList;
    protected void onCreate(Bundle savedInstanceState){
    	super.onCreate(savedInstanceState);
    	setContentView(R.layout.activity_animal);
    	initAnimals();
    	lvAnimalList=(ListView)findViewById(R.id.lvAnimalList);
    	AnimalAdapter animalAdapter=new AnimalAdapter(this,R.layout.animal_item,animalList);
        lvAnimalList.setAdapter(animalAdapter); 
        lvAnimalList.setOnItemClickListener(new OnItemClickListener(){

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view, int position,
					long id) {
				// TODO Auto-generated method stub
				Animal animal=animalList.get(position);
				String result=animal.getName()+"\n"+
				animal.getPronounce()+
				"\n【解释】:"+animal.getExplain()
				+"\n【近义词】:"+animal.getHomoionym()+
				"\n【反义词】:"+animal.getAntonym()+
				"\n【来源】:"+animal.getDerivation()+
				"\n【示例】:"+animal.getExamples();
				DialogUtil.showDialog(result,StudyAnimalActivity.this);
			}
        	
        });
    }
    
    private void initAnimals(){
    	animalDao=AnimalDao.getInstance(this);
    	animalList=animalDao.getAllAnimals();
    }
}
在layout新建布局文件dialog_info.xml
<?xml version="1.0" encoding="utf-8"?>
<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:background="@drawable/bg_ling"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/tvldiomInfo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium"/>
    </LinearLayout>
    

</ScrollView>
在util包下创建DialogUtil类
package cn.edu.bztc.happyidiom.util;

import cn.edu.bztc.happyidiom.R;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

public class DialogUtil {
  public static void showDialog(String result,Context context) {
  AlertDialog.Builder builder=new AlertDialog.Builder(context);
  LayoutInflater layoutInflater=LayoutInflater.from(context);
  View view=layoutInflater.inflate(R.layout.dialog_info, null);
  builder.setView(view);
  TextView tvldiomInfo=(TextView)view.findViewById(R.id.tvldiomInfo);
  tvldiomInfo.setText(result);
  builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
	@Override
	public void onClick(DialogInterface dialog, int which) {
		// TODO Auto-generated method stub
		dialog.dismiss();
	}
});
  builder.create().show();
  } 
}

由此该项目完成。

结果图如下:




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
完整版:https://download.csdn.net/download/qq_27595745/89522468 【课程大纲】 1-1 什么是java 1-2 认识java语言 1-3 java平台的体系结构 1-4 java SE环境安装和配置 2-1 java程序简介 2-2 计算机中的程序 2-3 java程序 2-4 java类库组织结构和文档 2-5 java虚拟机简介 2-6 java的垃圾回收器 2-7 java上机练习 3-1 java语言基础入门 3-2 数据的分类 3-3 标识符、关键字和常量 3-4 运算符 3-5 表达式 3-6 顺序结构和选择结构 3-7 循环语句 3-8 跳转语句 3-9 MyEclipse工具介绍 3-10 java基础知识章节练习 4-1 一维数组 4-2 数组应用 4-3 多维数组 4-4 排序算法 4-5 增强for循环 4-6 数组和排序算法章节练习 5-0 抽象和封装 5-1 面向过程的设计思想 5-2 面向对象的设计思想 5-3 抽象 5-4 封装 5-5 属性 5-6 方法的定义 5-7 this关键字 5-8 javaBean 5-9 包 package 5-10 抽象和封装章节练习 6-0 继承和多态 6-1 继承 6-2 object类 6-3 多态 6-4 访问修饰符 6-5 static修饰符 6-6 final修饰符 6-7 abstract修饰符 6-8 接口 6-9 继承和多态 章节练习 7-1 面向对象的分析与设计简介 7-2 对象模型建立 7-3 类之间的关系 7-4 软件的可维护与复用设计原则 7-5 面向对象的设计与分析 章节练习 8-1 内部类与包装器 8-2 对象包装器 8-3 装箱和拆箱 8-4 练习题 9-1 常用类介绍 9-2 StringBuffer和String Builder类 9-3 Rintime类的使用 9-4 日期类简介 9-5 java程序国际化的实现 9-6 Random类和Math类 9-7 枚举 9-8 练习题 10-1 java异常处理 10-2 认识异常 10-3 使用try和catch捕获异常 10-4 使用throw和throws引发异常 10-5 finally关键字 10-6 getMessage和printStackTrace方法 10-7 异常分类 10-8 自定义异常类 10-9 练习题 11-1 Java集合框架和泛型机制 11-2 Collection接口 11-3 Set接口实现类 11-4 List接口实现类 11-5 Map接口 11-6 Collections类 11-7 泛型概述 11-8 练习题 12-1 多线程 12-2 线程的生命周期 12-3 线程的调度和优先级 12-4 线程的同步 12-5 集合类的同步问题 12-6 用Timer类调度任务 12-7 练习题 13-1 Java IO 13-2 Java IO原理 13-3 流类的结构 13-4 文件流 13-5 缓冲流 13-6 转换流 13-7 数据流 13-8 打印流 13-9 对象流 13-10 随机存取文件流 13-11 zip文件流 13-12 练习题 14-1 图形用户界面设计 14-2 事件处理机制 14-3 AWT常用组件 14-4 swing简介 14-5 可视化开发swing组件 14-6 声音的播放和处理 14-7 2D图形的绘制 14-8 练习题 15-1 反射 15-2 使用Java反射机制 15-3 反射与动态代理 15-4 练习题 16-1 Java标注 16-2 JDK内置的基本标注类型 16-3 自定义标注类型 16-4 对标注进行标注 16-5 利用反射获取标注信息 16-6 练习题 17-1 顶目实战1-单机版五子棋游戏 17-2 总体设计 17-3 代码实现 17-4 程序的运行与发布 17-5 手动生成可执行JAR文件 17-6 练习题 18-1 Java数据库编程 18-2 JDBC类和接口 18-3 JDBC操作SQL 18-4 JDBC基本示例 18-5 JDBC应用示例 18-6 练习题 19-1 。。。
东南亚位于我国倡导推进的“一带一路”海陆交汇地带,作为当今全球发展最为迅速的地区之一,近年来区域内生产总值实现了显著且稳定的增长。根据东盟主要经济体公布的最新数据,印度尼西亚2023年国内生产总值(GDP)增长5.05%;越南2023年经济增长5.05%;马来西亚2023年经济增速为3.7%;泰国2023年经济增长1.9%;新加坡2023年经济增长1.1%;柬埔寨2023年经济增速预计为5.6%。 东盟国家在“一带一路”沿线国家中的总体GDP经济规模、贸易总额与国外直接投资均为最大,因此有着举足轻重的地位和作用。当前,东盟与中国已互相成为双方最大的交易伙伴。中国-东盟贸易总额已从2013年的443亿元增长至 2023年合计超逾6.4万亿元,占中国外贸总值的15.4%。在过去20余年中,东盟国家不断在全球多变的格局里面临挑战并寻求机遇。2023东盟国家主要经济体受到国内消费、国外投资、货币政策、旅游业复苏、和大宗商品出口价企稳等方面的提振,经济显现出稳步增长态势和强韧性的潜能。 本调研报告旨在深度挖掘东南亚市场的增长潜力与发展机会,分析东南亚市场竞争态势、销售模式、客户偏好、整体市场营商环境,为国内企业出海开展业务提供客观参考意见。 本文核心内容: 市场空间:全球行业市场空间、东南亚市场发展空间。 竞争态势:全球份额,东南亚市场企业份额。 销售模式:东南亚市场销售模式、本地代理商 客户情况:东南亚本地客户及偏好分析 营商环境:东南亚营商环境分析 本文纳入的企业包括国外及印尼本土企业,以及相关上下游企业等,部分名单 QYResearch是全球知名的大型咨询公司,行业涵盖各高科技行业产业链细分市场,横跨如半导体产业链(半导体设备及零部件、半导体材料、集成电路、制造、封测、分立器件、传感器、光电器件)、光伏产业链(设备、硅料/硅片、电池片、组件、辅料支架、逆变器、电站终端)、新能源汽车产业链(动力电池及材料、电驱电控、汽车半导体/电子、整车、充电桩)、通信产业链(通信系统设备、终端设备、电子元器件、射频前端、光模块、4G/5G/6G、宽带、IoT、数字经济、AI)、先进材料产业链(金属材料、高分子材料、陶瓷材料、纳米材料等)、机械制造产业链(数控机床、工程机械、电气机械、3C自动化、工业机器人、激光、工控、无人机)、食品药品、医疗器械、农业等。邮箱:market@qyresearch.com

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值