2012-01-25 64 views
0

如何遍历这组数据?处理来自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中存在另一个问题。

回答

0

图标参数是一个整数,而不是一个字符串。从你的代码看来,你传递的是一个字符串,这会给你一个编译错误。

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

存储这些,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.... 
+0

是的,我知道,我不知道如何使它发挥作用?我应该以另一种方式存储图像还是有像js中的eval这样的功能? –

+0

我已经更新了我的答案。 –