Android的 - 是否SimpleCursorAdapter允许多个布局像BaseAdapter? [英] Android - Does SimpleCursorAdapter allow multiple layouts like BaseAdapter?

查看:409
本文介绍了Android的 - 是否SimpleCursorAdapter允许多个布局像BaseAdapter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道你可以创建一个自定义的适配器延长 BaseAdapter 并创建可根据其膨胀各种布局排在适配器视图是..

但是,有没有什么办法让定制用一个简单的量 SimpleCursorAdapter

例如。我有一个数据库,我想进行查询,并将结果返回到的ListView 与交替行布局。

威尔 SimpleCursorAdapter 吗?还是有什么优雅的解决方案呢?

干杯

解决方案
  

但是,有没有什么办法让定制一个简单的量与SimpleCursorAdapter?

就像BaseAdapter,你可以扩展的CursorAdapter或SimpleCursorAdapter做您的自定义。

  

例如。我有一个数据库,我想进行查询,并将结果返回到ListView与交替行布局。

如果你只交了次要的东西像行的颜色,你可以简单地覆盖 bindView()和检查如果(cursor.getPosition() %2 == 0)(或 == 1 )来设置相应的背景颜色。

如果您使用的是不同类型的,或在每个布局视图的数字,你需要重写 getViewTypeCount() getItemViewType()。然后使用 getItemViewType() NewView的()加载适当的布局,并在 bindView( )来显示相应的数据。

I know you can create a custom Adapter extending BaseAdapter and create various layouts which can be inflated depending on which row the AdapterView is at..

But is there any way to get a simple amount of customization with a SimpleCursorAdapter?

Eg. I have a database and I would like to query it and return the results to a ListView with alternating row layouts.

Will SimpleCursorAdapter do? Or are there any elegant solutions for this?

Cheers

解决方案

But is there any way to get a simple amount of customization with a SimpleCursorAdapter?

Just like BaseAdapter, you can extend CursorAdapter or SimpleCursorAdapter to do your customization.

Eg. I have a database and I would like to query it and return the results to a ListView with alternating row layouts.

If you are only alternating a minor thing like row color, you can simply override bindView() and check if(cursor.getPosition() % 2 == 0) (or == 1) to set the appropriate background color.

If you are using different types of or numbers of Views in each layout, you need to override getViewTypeCount() and getItemViewType(). Then use getItemViewType() in newView() to load the appropriate layout and in bindView() to display the appropriate data.

这篇关于Android的 - 是否SimpleCursorAdapter允许多个布局像BaseAdapter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆