Advertisement
Guest User

Untitled

a guest
Apr 15th, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. // Adding menuItems to ListView
  2. SimpleAdapter adapter = new SimpleAdapter(getActivity(), menuItems,
  3. R.layout.list_item, new String[] { KEY_ALLARM_ID,
  4. KEY_DATETIME, KEY_CATEGORY, KEY_SUB_CATEGORY,
  5. KEY_USER_NAME, KEY_WIIL_HELP, KEY_NEED_HELP,
  6. KEY_DESCRIPTION, KEY_CATEGORY_ID,
  7. KEY_SUB_CATEGORY_ID, KEY_LAT, KEY_LNG,
  8. KEY_USER_PHONE }, new int[] { R.id.allarm_id,
  9. R.id.date_time, R.id.category, R.id.sub_category,
  10. R.id.user_name, R.id.will_help, R.id.need_help,
  11. R.id.description, R.id.category_id,
  12. R.id.sub_category_id, R.id.lat, R.id.lng,
  13. R.id.user_phone });
  14.  
  15. SimpleAdapter.ViewBinder binder = new SimpleAdapter.ViewBinder() {
  16. @Override
  17. public boolean setViewValue(View view, Object object, String value) {
  18. LayoutInflater inflater_my = (LayoutInflater)getActivity()
  19. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  20. View category_View = inflater_my.inflate(R.layout.list_item, null);
  21. if(view.getId() == R.id.category_id)
  22. {
  23. int converted=Integer.parseInt(value);
  24. TextView lblCategory = (TextView) category_View.findViewById(R.id.category);
  25.  
  26. switch (converted) {
  27. // LinearLayout
  28. case 1:
  29. {
  30. lblCategory.setTextColor(Color.RED);
  31. break;
  32. }
  33. case 2:
  34. {
  35. lblCategory.setTextColor(Color.MAGENTA);
  36. break;
  37. }
  38. case 3:
  39. {
  40. lblCategory.setTextColor(Color.GREEN);
  41. break;
  42. }
  43. case 4:
  44. {
  45. lblCategory.setTextColor(Color.BLUE);
  46. break;
  47. }
  48. }
  49. }
  50. return false;
  51. }
  52. };
  53. adapter.setViewBinder(binder);
  54. setListAdapter(adapter);
  55.  
  56. <TextView
  57. android:id="@+id/category"
  58. android:layout_width="wrap_content"
  59. android:layout_height="wrap_content"
  60. android:textSize="16sp"
  61. android:textStyle="bold"
  62. android:paddingLeft="10dp"
  63. android:gravity="left">
  64. </TextView>
  65. <TextView
  66. android:id="@+id/sub_category_id"
  67. android:layout_width="wrap_content"
  68. android:layout_height="wrap_content"
  69. android:textColor="#000000"
  70. android:textStyle="normal"
  71. android:visibility="gone"
  72. android:gravity="left">
  73. </TextView>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement