Guest User

Untitled

a guest
Aug 15th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. ListView items fading when scrolling in Android
  2. public class TasksAdapter extends BaseAdapter {
  3.  
  4. private String[] items;
  5. private int[] priorities;
  6. private Vector<String> completed;
  7. private Context context;
  8.  
  9. public TasksAdapter(TasksActivity context, int textViewResourceId, String[] items) {
  10. if(items != null)
  11. this.items = items;
  12. else
  13. this.items = new String[0];
  14.  
  15. this.priorities = new int[this.items.length];
  16. for(int i = 0; i < this.priorities.length; i++) {
  17. this.priorities[i] = FMN.PRIORITY_LOW;
  18. }
  19.  
  20. this.completed = new Vector<String>(0);
  21.  
  22. this.context = context;
  23. }
  24.  
  25. public TasksAdapter(TasksActivity context, int textViewResourceId, String[] items, int[] priorities, Vector<String> completed) {
  26. if(items != null)
  27. this.items = items;
  28. else
  29. this.items = new String[0];
  30.  
  31. if(priorities != null)
  32. this.priorities = priorities;
  33. else {
  34. this.priorities = new int[this.items.length];
  35. for(int i = 0; i < this.priorities.length; i++) {
  36. this.priorities[i] = FMN.PRIORITY_LOW;
  37. }
  38. }
  39.  
  40. if(completed != null)
  41. this.completed = completed;
  42. else
  43. this.completed = new Vector<String>(0);
  44.  
  45. this.context = context;
  46. }
  47.  
  48. public View getView(int position, View convertView, ViewGroup parent) {
  49. View v = convertView;
  50.  
  51. if (v == null) {
  52. LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  53. v = vi.inflate(R.layout.task_item, null);
  54. }
  55.  
  56. TextView task = (TextView) v.findViewById(R.id.tv_task);
  57. task.setText(items[position]);
  58.  
  59. ImageView prio = (ImageView) v.findViewById(R.id.im_task_priority);
  60.  
  61. switch(priorities[position]) {
  62. case FMN.PRIORITY_HIGH:
  63. prio.setImageResource(R.drawable.fmn_priority_high);
  64. break;
  65.  
  66. case FMN.PRIORITY_MEDIUM:
  67. prio.setImageResource(R.drawable.fmn_priority_low);
  68. break;
  69.  
  70. case FMN.PRIORITY_LOW:
  71. prio.setImageResource(R.drawable.fmn_priority_medium);
  72. break;
  73.  
  74. default:
  75. prio.setImageResource(R.drawable.fmn_priority_medium);
  76. break;
  77. }
  78.  
  79. if((completed.size() != 0) && (completed.contains(task.getText()))) {
  80. task.setTextColor(Color.rgb(155, 175, 155));
  81. }
  82.  
  83. return v;
  84. }
  85.  
  86. public int getCount() {
  87. return items.length;
  88. }
  89.  
  90. public Object getItem(int position) {
  91. return position;
  92. }
  93.  
  94. public long getItemId(int position) {
  95. return position;
  96. }
  97.  
  98. }
  99.  
  100. if((completed.size() != 0) && (completed.contains(task.getText()))) {
  101. task.setTextColor(Color.rgb(155, 175, 155));
  102. }
  103.  
  104. if((completed.size() != 0) && (completed.contains(task.getText()))) {
  105. task.setTextColor(Color.rgb(155, 175, 155));
  106. } else {
  107. task.setTextColor(Color.rgb(0, 0, 0));
  108. }
Add Comment
Please, Sign In to add comment