乐学成语案例分析
来源:互联网 发布:linux mv f 目录非空 编辑:程序博客网 时间:2024/04/29 23:23
<pre name="code" class="html"><pre class="java" name="code">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); initCategory();//初始化类 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 Intent intent; switch(position){ case 0: intent=new Intent(StudyActivity.this,StudyAnimalActivity.class); startActivity(intent); break; case 6: intent=new Intent(StudyActivity.this,StudyOtherActivity.class); startActivity(intent); break; default: break; } } }); } private void initCategory() { // 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])); } } @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; } } <img src="http://img.blog.csdn.net/20160615133812641?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" width="310" height="407" alt="" />
public class DBOpenHelper { private final int BUFFER_SIZE=400000;//缓冲区大小 public static final String DB_NAME="idioms.db"; //保存的数据库文件名 public static final String PACKAGE_NAME="com.example.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; } }
public class DBOpenHelper { private final int BUFFER_SIZE=400000;//缓冲区大小 public static final String DB_NAME="idioms.db"; //保存的数据库文件名 public static final String PACKAGE_NAME="com.example.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; } }
0 0
- 乐学成语案例分析
- 乐学成语案例
- Android乐学成语的实现分析
- 个人完成案例之乐学成语(测试篇)
- 乐学成语
- 乐学成语
- 乐学成语
- 乐学成语2
- 乐学成语
- 乐学成语
- Android---乐学成语
- 乐学成语
- 乐学成语
- 乐学成语2
- 17乐学成语
- 18乐学成语
- 19乐学成语
- 乐学成语作业
- linux下编译安装libcurl(附使用示例)
- 顺应潮流 - Sun公司软件开源经历对今天的启发
- 详解Linux开机自动启动SVN原理
- 运用QML制作圆形进度条效果
- 添加水印
- 乐学成语案例分析
- 【翻译】Android Support Library Features(二)
- 如何实现android跳转页面并传递参数
- 什么内网和外网
- channel
- 【android】getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()的作用,getfilesdir
- Android实现授权访问网页的方法
- Android Studio设置颜色拾色器工具Color Picker
- 不等式的研究