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进行信息的输入 ...
随机推荐
- Android 物理按键
import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view. ...
- [Angular 2] Handling Clicks and Intervals Together with Merge
Observable.merge allows you take two different source streams and use either one of them to make cha ...
- 外键约束列并没有导致大量建筑指数library cache pin/library cache lock
外键约束列并没有导致大量建筑指数library cache pin/library cache lock 清除一个100大数据表超过一百万线,发现已经运行了几个小时: delete B001.T_B1 ...
- [转] 为什么医疗咨询服务公司Evolent Health仅用4年就华丽上市?
让医疗主体,即医院和医生担任保险角色,完全控制保费,实现医疗机构的利益最大化.美国公司EvolentHealth帮助所有医院实现这一梦想. 不觉间,已步入2015的下半年.当国内还在讨论商业保险何时能 ...
- CSS选择符详解之关系选择符篇
原文:http://www.chinaz.com/web/2012/1017/278553.shtml 相信大家都对CSS选择符都不陌生,选择符包含:元素选择符.关系选择符.属性选择符.伪类选择符.伪 ...
- phpmyadmin设置id自增(AUTO_INCREMENT)(转)
phpmyadmin设置id自增(AUTO_INCREMENT) 在A_I 前面打勾:如图 AUTO_INCREMENT =A_I 查看效果
- PHP编程规范
好的编程规范不仅是对阅读者的负责,也是对自身的负责: ----割---- 一直以来我都是以php函数的风格来写php,所有变量,函数,类都使用小写,单词之间以下划线隔开,一直比较排斥驼峰式的代码规范, ...
- j2ee开发中的“java容器”和“web容器”有什么区别?
http://blog.csdn.net/zi_jun/article/details/7387259
- Java实现多线程下载
package cn.test.DownLoad; import java.io.File; import java.io.InputStream; import java.io.RandomAcce ...
- 《Linux内核分析》 week8作业-Linux加载和启动一个可执行程序
一.ELF文件格式 ELF(Executable and Linking Format)是x86 Linux系统下常用的目标文件格式,有三种主要类型: 适于连接的可重定位文件,可与其他目标文件一起创建 ...