android SimpleCursorAdapter的使用
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的使用的更多相关文章
- Android学习之适配器SimpleCursorAdapter
三. SimpleCursorAdapter与SimpleAdapter用法相近.只是将List对象换成了Cursor对象.而且SimpleCursorAdapter类构造方法的第四个参数from ...
- android中SimpleCursorAdapter _id错误的问题
作为一个android新手,在绑定数据的时候是这样的 ListView listview=(ListView)this.findViewById(R.id.listView1); XJDal xj=n ...
- 使用具体解释及源代码解析Android中的Adapter、BaseAdapter、ArrayAdapter、SimpleAdapter和SimpleCursorAdapter
Adapter相当于一个数据源,能够给AdapterView提供数据.并依据数据创建相应的UI.能够通过调用AdapterView的setAdapter方法使得AdapterView将Adapter作 ...
- Android开发模板------自己定义SimpleCursorAdapter的使用
使用SimpleCursorAdapter所设计的table(数据表)一定要有_id字段名称,否则会出现"找不到_id"的错误 SimpleCursorAdapter直接使用的方法 ...
- 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 ...
- Android软件开发之ListView 详解【转】
ListView的使用方法 ListView是Android软件开发中非常重要组件之一,基本上是个软件基本都会使用ListView ,今天我通过一个demo来教大家怎么样使用ListView组件 绘 ...
- Android开发自学笔记(Android Studio)—4.4 AdapterView及其子类
一.引言 AdapterView本身是一个抽象类,而它派生的子类在用法上也基本相似,只是在显示上有一定区别,因此把他们也归为一类. AdapterView具有如下特征: Ada ...
- Android ORM 框架之 greenDAO 使用心得
前言 我相信,在平时的开发过程中,大家一定会或多或少地接触到 SQLite.然而在使用它时,我们往往需要做许多额外的工作,像编写 SQL 语句与解析查询结果等.所以,适用于 Android 的ORM ...
- 详细解读Android中的搜索框—— SearchView
以前总是自己写的 今天看看别人做的 本篇讲的是如何用searchView实现搜索框,其实原理和之前的没啥差别,也算是个复习吧. 一.Manifest.xml 这里我用一个activity进行信息的输入 ...
随机推荐
- Robotium--takeScreenshot(截图)
在Robotium中,截图的方法时调用takeScreenshot(). 但有使用你会发现明明代码里调用了solo.takeScreenshot(),但却没有截图成功,那是因为被测试的应用没有SD卡的 ...
- ListActivity ListView 使用 介绍 用法
ListActivity简单的说就是ListView和Activity的结合,跟ListView和Activity组合实现的没有什么很大的差别,主要是比较方便. 在实现时,要注意: 1.一般情况,Li ...
- nosqlunit开源框架
import com.lordofthejars.nosqlunit.annotation.UsingDataSet;import com.lordofthejars.nosqlunit.core.L ...
- MD5加密类
public class MD5Util { public static String getMD5(String s) { char hexDigits[] = {'0', '1', '2', '3 ...
- 自定义圆形imageview
import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapShader ...
- c - 统计字符串"字母,空格,数字,其他字符"的个数和行数.
#include <stdio.h> #include <ctype.h> using namespace std; /* 题目:输入一行字符,分别统计出其中英文字母.空格.数 ...
- CentOS 6.4搭建zabbix
系统环境:CentOS 6.4 64bit Zabbix版本:zabbix 2.2.3 前提条件:已安装好LNMP环境 一.服务端: 1. 下载zabbix安装包zabbix-2.2.3.tar.g ...
- Ubuntu 11.10开启root用户登陆
以管理员身份运行 #sudo gedit /etc/lightdm/lightdm.conf 将里面改成 "autologin-user=root" 就可以以root用户登录了
- ubuntu11.10(TQ210)下移植boa服务器
平台:ubuntu11.10 一.下载源码包www.boa.org boa-0.94.13.tar.gz 二.解压,在其src目录下生产makefile #tar xvfz boa-0.94.1 ...
- php开发通用采集程序
php采集程序构建基本步骤: 采集程序是什么?获取远程数据(文字.图片.图片)并快速保存到本地或指定地址. 如天气预报(小偷程序): 远程获取-->替换内容-->展示给用户 如实时更新的新 ...