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.
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....