开发者

simplecursoradapter treat field as integer resource value

开发者 https://www.devze.com 2023-04-12 03:11 出处:网络
I have some data in a table on my database. On a column I have integer values that refer to a string resource.

I have some data in a table on my database. On a column I have integer values that refer to a string resource.

I want that when I load the values with my adapter my ListView display the String related to the value, but not the integer value itself.

    String[] nfrom = {ProfileManager.EVENT_NAME,ProfileManager.NAME,ProfileManager.PRIORITY};
    int[] nto = {R.id.eventType,R.id.profileToSwitch,R.id.priority};

    triggersCursor = profileManager.getAllModTriggerCursors();
    start开发者_开发技巧ManagingCursor(triggersCursor);
    triggersAdapter = new SimpleCursorAdapter(this,R.layout.trigger_item_layout,triggersCursor,nfrom,nto);
    lst_triggers.setAdapter(triggersAdapter);

The ListView display '2131034132', not the String.

I hope my explanation is clear.

Thanks in advance!


Use a SimpleCursorAdapter.ViewBinder to customize the binding process for this field. For Example:

setViewValue(...){
   boolean isCustomBinding = false;

   if(view.getId() == R.id.my_id){
       TextView tv = (TextView) view;
       tv.setText(cursor.getInt(columnIndex));
       isCustomBinding = true;
   }

   return isCustomBinding; // returning false will allow the automatic binder to work.
}
0

精彩评论

暂无评论...
验证码 换一张
取 消