处理来自 SQLite/Android 的数据
如何遍历这组数据呢?
String[] from = new String[]{AppSQLite.KEY_NAME,AppSQLite.KEY_ICON};
int[] to = new int[]{R.id.main_menu_list_item);
我想将它们传递给自定义的简单光标适配器并重写 getView() 以便 KEY_NAME 是文本(可能带有 setText),
setCompoundDrawablesWithIntrinsicBounds(**KEY_ICON**, 0, 0, 0);
我的 getView 是这样的:
public View getView(int pos, View convertView, ViewGroup parent){
View v = convertView;
if(v == null){
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.icon_list_item, null);
}
this.c.moveToPosition(pos);
String name= this.c.getString(this.c.getColumnIndex(AppSQLite.KEY_NAME));
String icon= this.c.getString(this.c.getColumnIndex(AppSQLite.KEY_ICON));
TextView mName= (TextView) v.findViewById(R.id.icon_textView);
bTitle.setText(name);
mName.setCompoundDrawablesWithIntrinsicBounds(icon, 0, 0, 0);
return v;
在我的数据库中,图标采用这种形式:
R.drawable.menu_icon TEXT
所以我认为将值放入 setCompoundDrawablesWithIntrinsicBounds
中还有另一个问题。
How can I traverse through this set of data?
String[] from = new String[]{AppSQLite.KEY_NAME,AppSQLite.KEY_ICON};
int[] to = new int[]{R.id.main_menu_list_item);
I want to pass them to a custom simple cursor adapter and override getView() so that
the KEY_NAME is the text (with setText probably) and
setCompoundDrawablesWithIntrinsicBounds(**KEY_ICON**, 0, 0, 0);
My getView is this:
public View getView(int pos, View convertView, ViewGroup parent){
View v = convertView;
if(v == null){
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.icon_list_item, null);
}
this.c.moveToPosition(pos);
String name= this.c.getString(this.c.getColumnIndex(AppSQLite.KEY_NAME));
String icon= this.c.getString(this.c.getColumnIndex(AppSQLite.KEY_ICON));
TextView mName= (TextView) v.findViewById(R.id.icon_textView);
bTitle.setText(name);
mName.setCompoundDrawablesWithIntrinsicBounds(icon, 0, 0, 0);
return v;
In my db the icon is in this form:
R.drawable.menu_icon TEXT
So I think there is another problem with putting the value in setCompoundDrawablesWithIntrinsicBounds
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
icon 参数是一个整数,而不是一个字符串。从您的代码来看,您似乎正在传递一个字符串,这应该会给您带来编译错误。
更新:在数据库中存储一些字符串,并编写逻辑来加载不同的可绘制对象。
存储这些,icon_1,icon_2,icon_3
The icon parameter is an integer, and not a string. From your code, it seems that you are passing a string, which should give you a compile error.
Update: Store some strings in the database, and write logic to load different drawables.
Store these, icon_1, icon_2, icon_3