Android:BaseAdapter 怎么做? [英] Android : BaseAdapter how to?

查看:22
本文介绍了Android:BaseAdapter 怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

I have been able to implement a Simple Cursor Adapter http://developer.android.com/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 怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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