Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ListView items fading when scrolling in Android
- public class TasksAdapter extends BaseAdapter {
- private String[] items;
- private int[] priorities;
- private Vector<String> completed;
- private Context context;
- public TasksAdapter(TasksActivity context, int textViewResourceId, String[] items) {
- if(items != null)
- this.items = items;
- else
- this.items = new String[0];
- this.priorities = new int[this.items.length];
- for(int i = 0; i < this.priorities.length; i++) {
- this.priorities[i] = FMN.PRIORITY_LOW;
- }
- this.completed = new Vector<String>(0);
- this.context = context;
- }
- public TasksAdapter(TasksActivity context, int textViewResourceId, String[] items, int[] priorities, Vector<String> completed) {
- if(items != null)
- this.items = items;
- else
- this.items = new String[0];
- if(priorities != null)
- this.priorities = priorities;
- else {
- this.priorities = new int[this.items.length];
- for(int i = 0; i < this.priorities.length; i++) {
- this.priorities[i] = FMN.PRIORITY_LOW;
- }
- }
- if(completed != null)
- this.completed = completed;
- else
- this.completed = new Vector<String>(0);
- this.context = context;
- }
- public View getView(int position, View convertView, ViewGroup parent) {
- View v = convertView;
- if (v == null) {
- LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- v = vi.inflate(R.layout.task_item, null);
- }
- TextView task = (TextView) v.findViewById(R.id.tv_task);
- task.setText(items[position]);
- ImageView prio = (ImageView) v.findViewById(R.id.im_task_priority);
- switch(priorities[position]) {
- case FMN.PRIORITY_HIGH:
- prio.setImageResource(R.drawable.fmn_priority_high);
- break;
- case FMN.PRIORITY_MEDIUM:
- prio.setImageResource(R.drawable.fmn_priority_low);
- break;
- case FMN.PRIORITY_LOW:
- prio.setImageResource(R.drawable.fmn_priority_medium);
- break;
- default:
- prio.setImageResource(R.drawable.fmn_priority_medium);
- break;
- }
- if((completed.size() != 0) && (completed.contains(task.getText()))) {
- task.setTextColor(Color.rgb(155, 175, 155));
- }
- return v;
- }
- public int getCount() {
- return items.length;
- }
- public Object getItem(int position) {
- return position;
- }
- public long getItemId(int position) {
- return position;
- }
- }
- if((completed.size() != 0) && (completed.contains(task.getText()))) {
- task.setTextColor(Color.rgb(155, 175, 155));
- }
- if((completed.size() != 0) && (completed.contains(task.getText()))) {
- task.setTextColor(Color.rgb(155, 175, 155));
- } else {
- task.setTextColor(Color.rgb(0, 0, 0));
- }
Add Comment
Please, Sign In to add comment