Android:BaseAdapter 如何?
好吧,我一直在仔细搜索,并且在实现 BaseAdapter 时遇到了一些问题。
我已经能够实现一个简单的光标适配器 http://开发人员。 android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List7.html 按照上面的示例。
这里有一个非常好的 BaseAdapter 示例: List14 google 示例
我想使用 BaseAdapter 创建自己的列表适配器来显示 listView,其中包含数据库中的多个项目。 我知道这可以使用简单游标适配器来完成,但我希望以不同的方式处理行,因此我希望能够通过重写 getView 来绘制每一行。 数据将从游标中提取。
我知道这段代码对于获取光标数据来说很难看,但假设我已经填充了光标。 如果第 8 列包含图像资源 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 的好例子吗?
Ok, I have been searching thick and thin, and I am having some issues implementing a BaseAdapter.
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.
There is a pretty good BaseAdapter example here : List14 google example
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.
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;
}
Do you have any good examples of a BaseAdapter being drawn using a cursor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试从
BaseAdapter
本身内部的方法调用notifyDataSetChanged()
。请参阅 List8 中的方法以API演示为例。
Try calling
notifyDataSetChanged()
from a method inside theBaseAdapter
itself.See the methods in List8 of the API Demos as an example.