Created
July 31, 2010 12:18
-
-
Save bartvandendriessche/502120 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override | |
| public View getView(final int position, final View convertView, final ViewGroup parent) { | |
| View row = convertView; | |
| if (row == null) { | |
| LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
| row = vi.inflate(layout, null); | |
| } | |
| final TimeEntryRowModel entry = getItem(position); | |
| if (entry != null) { | |
| row.setBackgroundColor(getContext().getResources().getColor(ColorUtil.getRandomBlockColor(entry.getProjectName()))); | |
| // handle the comment button | |
| row.findViewById(R.id.comment).setBackgroundColor(getContext().getResources().getColor(ColorUtil.getRandomDarkBlockColor(entry.getProjectName()))); | |
| // if there is a comment, change image to the dotted text bubble | |
| if (entry.getEntry().getDescription() != null && !"".equals(entry.getEntry().getDescription())) { | |
| ((ImageView) row.findViewById(R.id.comment_icon)).setImageResource(R.drawable.comment_on); | |
| } | |
| // initialize time entry name and task name | |
| ((TextView) row.findViewById(R.id.time_entry_name)) | |
| .setText(String.format("%s [%s]", entry.getProjectName(), entry.getProjectCompanyName())); | |
| ((TextView) row.findViewById(R.id.time_entry_task)) | |
| .setText(entry.getTodoName()); | |
| // handle the hours text fields | |
| ((TextView) row.findViewById(R.id.time_tracking_total_hours)) | |
| .setText(Integer.toString(NumberFormatUtil.getDoubleIntegerUnits(entry.getEntry().getHours()))); | |
| ((TextView) row.findViewById(R.id.time_tracking_total_hours_fraction)) | |
| .setText(Integer.toString(NumberFormatUtil.getDoubleDecimalUnits(entry.getEntry().getHours()))); | |
| } | |
| return row; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
| <item android:state_pressed="true" android:color="@drawable/block_purple_dark" /> | |
| <item android:color="@drawable/block_purple"/> | |
| </selector> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Right, the solution to having ListView rows change colour based on their state is to just create a selector Drawable instead of a selector Color. Then call row.setBackgroundDrawable instead of row.setBackgroundColor during setup.