Android:BaseAdapter 怎么做?

编程入门 行业动态 更新时间:2024-10-24 20:16:59
本文介绍了Android:BaseAdapter 怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

好的,我一直在搜索,但在实现 BaseAdapter 时遇到了一些问题.

Ok, I have been searching thick and thin, and I am having some issues implementing a BaseAdapter.

我已经能够实现一个简单的光标适配器developer.android/resources/samples/ApiDemos/src/com/example/android/apis/view/List7.html 如上例所示.

I have been able to implement a Simple Cursor Adapter developer.android/resources/samples/ApiDemos/src/com/example/android/apis/view/List7.html as per the example above.

这里有一个很好的 BaseAdapter 示例:List14 谷歌示例

There is a pretty good BaseAdapter example here : List14 google example

我想使用 BaseAdapter 创建我自己的列表适配器来显示一个列表视图,其中包含来自数据库的多个项目.我知道这可以使用 Simple Cursor Adapter 来完成,但我希望以不同的方式处理行,所以我希望能够通过覆盖 getView 来绘制每一行.数据将从游标中拉出.

I am wanting to create my own List Adapter using BaseAdapter to show a listView, with multiple items from a Database. I know this can be done using the Simple Cursor Adapter, but I am looking to handle rows differently, so I want to be able to draw each row by overriding getView. The data would be pulled from a cursor.

我知道这段代码对于获取游标数据来说很丑陋,但假设我已经填充了一个游标.如果第 8 列包含图像资源 ID,您对此有何建议.:

I know this code is ugly for getting to the cursor data, but assuming I have populated a cursor. What suggestions do you have on this if column 8 contains the image resource id. :

@Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub cursor.moveToPosition(position); ImageView i = new ImageView(mContext); i.setImageResource(cursor.getShort(8)); i.setAdjustViewBounds(true); i.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); return i; }

您有使用光标绘制 BaseAdapter 的好例子吗?

Do you have any good examples of a BaseAdapter being drawn using a cursor?

推荐答案

尝试从 BaseAdapter 自身内部的方法调用 notifyDataSetChanged().

Try calling notifyDataSetChanged() from a method inside the BaseAdapter itself.

查看中的方法以 API Demo 的 List8 为例.

更多推荐

Android:BaseAdapter 怎么做?

本文发布于:2023-10-26 09:34:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529773.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:怎么做   Android   BaseAdapter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!