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. ios AFNetworking 有用篇

    在寻常开发中,af是个非常好用的东西.非常喜欢.可是网上的af找了好多都不太全面,不有用.所以我今天做了一个demo.有上传下载的. 比較有用.希望大家可以用到. 去我github下载demo git ...

  2. 跨平台传输中使用base64来保证非ascii码字符串的完整性

    首先,我们来看一个例子: byte[] b=new byte[]{2,9,43}; String ss=new String(b,"utf-8"); byte[] b1=ss.ge ...

  3. Win7系统安装MySQL5.5.21图解教程

    转自:http://www.jb51.net/article/37310.htm 这篇文章主要介绍了如何在win7中安装mysql,所以加上了MySQL的下载过程,希望对需要的人有所帮助 大家都知道M ...

  4. 富文本 SpannableString Span

    经典使用场景 SpannableStringBuilder needStartSSB = new SpannableStringBuilder("需要"); SpannableSt ...

  5. codevs 1269 匈牙利游戏

    /*暴力+乱搞 55分(似乎只有暴力得分了)*/ #include<iostream> #include<cstdio> #include<cstring> #in ...

  6. 第1章 你真的了解C#吗?

    什么是C#? C#是由微软公司开发的一种面向对象且运行于.Net Framework之上的高级程序设计语言,发布于2000年6月. 什么是.Net Framework 我们可以这样去理解.Net Fr ...

  7. POJ2449

    #include<stdio.h> #include<iostream> #include<queue> #include<vector> using ...

  8. css中同时用头部引入和外部引入对同一个标签进行样式设置,哪一个优先级高。

    这段是html中的代码 <!doctype html> <html lang="en"> <head> <meta charset=&qu ...

  9. Hyper-V虚拟机和主机的网络配置

    Hyper-V虚拟机和主机的网络配置 方式1.共享式 这种方式是将Hyper-V内部的虚拟网络与外部网络共享.使得内部是一个私有的网络.属于NAT的类型.(不知道这么说对不对) 优点: 相对来说属于私 ...

  10. SpringMVC简单例子

    http://www.cnblogs.com/wawlian/archive/2012/11/17/2775435.html