安卓:BaseAdapter如何? [英] Android : BaseAdapter how to?

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

问题描述

好吧,我一直在寻找厚,薄,我有一些问题,实施BaseAdapter。

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

我已经能够实现一个简单的游标适配器 <一href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List7.html" rel="nofollow">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.

有一个pretty的很好的BaseAdapter这里例如:<一href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html"相对=nofollow> List14谷歌的例子

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

我想使用BaseAdapter显示一个ListView创建自己的表适配器,与数据库中的多个项目。我知道这可以通过使用简单的游标适配器来完成,但我期待以不同方式处理行,所以我希望能够通过覆盖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.

我知道这code是丑陋获取光标数据,但假设我有填充游标。你有没有在这一点,如果第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?

推荐答案

尝试调用 notifyDataSetChanged()从内部的方法 BaseAdapter 本身。

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

见<一的方法href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List8.html"相对=nofollow>的API演示的List8 作为一个例子。

这篇关于安卓:BaseAdapter如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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