String[] fields=new String[]{"foodname","price","taste","stuff","make","image"};
final int[] Id=new int[]{R.id.FoodName,R.id.FoodPrice,R.id.FoodTaste,R.id.FoodStuff,R.id.FoodMake,R.id.FoodPhoto};
@SuppressWarnings("deprecation") ListAdapter adapter=new SimpleCursorAdapter(this, R.layout.fooddetil_content, cursor, fields, Id);
     listview.setadapter(adapter);
FoodDetilsListView.setAdapter(adapter);
//将数据绑定到自定义中的各个空中显示出来
((SimpleCursorAdapter) adapter).setViewBinder(new ViewBinder ()
{
public boolean setViewValue(View view, Cursor cursor,int columnIndex)
{
for(int i=0;i<6;i++)
{
if(view.findViewById(Id[i]) instanceof ImageView)
{
ImageView imageView = (ImageView) view.findViewById(Id[i]);
//得到数据库中存放的图片信息,并把它存放到byte数组中
byte[] image=cursor.getBlob(cursor.getColumnIndex("image"));
//把数组中的数据封装到bitmap对象中,让后通过setimagebitmap方法显示到imageView控件中
Bitmap bitmap=BitmapFactory.decodeByteArray(image, 0, image.length);
imageView.setImageBitmap(bitmap);
}
else if(view.findViewById(Id[i]) instanceof TextView)
{
try {
if(i==0)
{
//获取textview控件
TextView name=(TextView) view.findViewById(Id[i]);
//通过cursor对象找到foodname字段,并设置它的编码格式,然后显示到控件中去
String FoodName=new String(cursor.getString(cursor.getColumnIndex("foodname")).getBytes(),"utf-8");
name.setText(FoodName);
}else if(i==1)
{
TextView FoodPrice=(TextView) view.findViewById(Id[i]);
String FoodPrices = new String(cursor.getString(cursor.getColumnIndex("price")).getBytes(),"utf-8");
FoodPrice.setText("售价:"+FoodPrices+"元(每 份/个)");
}
else if(i==2)
{
TextView FoodTaste=(TextView) view.findViewById(Id[i]);
String taste=new String(cursor.getString(cursor.getColumnIndex("taste")).getBytes(),"utf-8");
FoodTaste.setText("口味:"+taste);
}
else if(i==3)
{
TextView FoodStuff=(TextView) view.findViewById(Id[i]);
String stuff=new String(cursor.getString(cursor.getColumnIndex("stuff")).getBytes(),"utf-8");
FoodStuff.setText("食材: "+stuff);
}
else
{
String Make = "";
TextView FoodMake=(TextView) view.findViewById(Id[i]);
String make=cursor.getString(cursor.getColumnIndex("make"));
String[] a=make.split("/");
for(int b=0;i<a.length;b++)
{
Make+=a[b]+"\n\n";
FoodMake.setText(Make);
}
} }
catch (Exception e)
{
e.printStackTrace();
} } }
return true;
}});

 

android SimpleCursorAdapter的使用的更多相关文章

  1. Android学习之适配器SimpleCursorAdapter

    三.   SimpleCursorAdapter与SimpleAdapter用法相近.只是将List对象换成了Cursor对象.而且SimpleCursorAdapter类构造方法的第四个参数from ...

  2. android中SimpleCursorAdapter _id错误的问题

    作为一个android新手,在绑定数据的时候是这样的 ListView listview=(ListView)this.findViewById(R.id.listView1); XJDal xj=n ...

  3. 使用具体解释及源代码解析Android中的Adapter、BaseAdapter、ArrayAdapter、SimpleAdapter和SimpleCursorAdapter

    Adapter相当于一个数据源,能够给AdapterView提供数据.并依据数据创建相应的UI.能够通过调用AdapterView的setAdapter方法使得AdapterView将Adapter作 ...

  4. Android开发模板------自己定义SimpleCursorAdapter的使用

    使用SimpleCursorAdapter所设计的table(数据表)一定要有_id字段名称,否则会出现"找不到_id"的错误 SimpleCursorAdapter直接使用的方法 ...

  5. Andriod学习笔记2:“Your content must have a ListView whose id attribute is 'android.R.id.list'”问题的解决办法

    问题描述 activity_main.xml代码如下: <?xml version="1.0" encoding="utf-8"?> <Lin ...

  6. Android软件开发之ListView 详解【转】

    ListView的使用方法  ListView是Android软件开发中非常重要组件之一,基本上是个软件基本都会使用ListView ,今天我通过一个demo来教大家怎么样使用ListView组件 绘 ...

  7. Android开发自学笔记(Android Studio)—4.4 AdapterView及其子类

    一.引言       AdapterView本身是一个抽象类,而它派生的子类在用法上也基本相似,只是在显示上有一定区别,因此把他们也归为一类.       AdapterView具有如下特征: Ada ...

  8. Android ORM 框架之 greenDAO 使用心得

    前言 我相信,在平时的开发过程中,大家一定会或多或少地接触到 SQLite.然而在使用它时,我们往往需要做许多额外的工作,像编写 SQL 语句与解析查询结果等.所以,适用于 Android 的ORM  ...

  9. 详细解读Android中的搜索框—— SearchView

    以前总是自己写的 今天看看别人做的 本篇讲的是如何用searchView实现搜索框,其实原理和之前的没啥差别,也算是个复习吧. 一.Manifest.xml 这里我用一个activity进行信息的输入 ...

随机推荐

  1. android 中如何限制 EditText 最大输入字符数

    方法一: 在 xml 文件中设置文本编辑框属性作字符数限制 如:android:maxLength="10" 即限制最大输入字符个数为10 方法二: 在代码中使用InputFilt ...

  2. Android实现计时与倒计时(限时抢购)的几种方法

    在购物网站的促销活动中一般都有倒计时限制购物时间或者折扣的时间,这些都是如何实现的呢? 在一个安卓客户端项目中恰好遇到了类似的问题,一开始使用的是Timer与 TimerTask, 虽然此方法通用,但 ...

  3. IntelliJ IDEA 中module的dependencies是其它module时的注意事项

    Dependencies on other modules If a module (module A) depends on another module (module B), IntelliJ ...

  4. Android - ContentProvider机制

    以下资料摘录整理自老罗的Android之旅博客,是对老罗的博客关于Android底层原理的一个抽象的知识概括总结(如有错误欢迎指出)(侵删):http://blog.csdn.net/luosheng ...

  5. 美洽SDK

    简介 GitHub地址:https://github.com/Meiqia/MeiqiaSDK-Android 开发文档:http://meiqia.com/docs/meiqia-android-s ...

  6. jQuery中使用 .html() function在IE8和9中显示不正常源码中多出sizset和sizcache

    错误原因:在引入jquery的时候,使用了html function,在IE8和IE9下面有可能会出现不兼容 解决办法:在html头部加一句 <meta http-equiv="X-U ...

  7. maven第5章坐标和依赖

    5.5依赖范围 runtime:运行时依赖范围 举的例子是JDBC驱动实现,不理解? 编译的时候只需要引入jdk提供的jdbc类和方法,比如java.sql.*;这时编译没有报错,但是没有引入mysq ...

  8. 安装 SQL Server2008 安装程序规则支持提示“重新启动计算机”失败

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager 删除 PendingFileRenameOperations这个 ...

  9. Linux && vim 批量替换

    Linux批量文件的字符串替换 sed -i "s/oldstring/newstring/g" `grep oldstring -rl path` vim多行替换::1,2s/s ...

  10. rsync从windows到linux的同步备份

    名称 角色 IP地址 Windows server 2003 服务器 Eth0:192.168.1.1 RHEL5.5 客户端 Eth0:192.168.1.2   一.cwRsyncServer服务 ...