处理来自 SQLite/Android 的数据

发布于 2024-12-29 00:51:27 字数 1190 浏览 0 评论 0原文

如何遍历这组数据呢?

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零崎曲识 2025-01-05 00:51:27

icon 参数是一个整数,而不是一个字符串。从您的代码来看,您似乎正在传递一个字符串,这应该会给您带来编译错误。

更新:在数据库中存储一些字符串,并编写逻辑来加载不同的可绘制对象。

存储这些,icon_1,icon_2,icon_3

if(icon_1){
   use R.drawable.icon_1;
else if(icon_2)
   use R.drawable.icon_2;
and so on....

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

if(icon_1){
   use R.drawable.icon_1;
else if(icon_2)
   use R.drawable.icon_2;
and so on....
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文