Created
December 24, 2013 02:27
-
-
Save daichan4649/8107982 to your computer and use it in GitHub Desktop.
TextView の文字色を default色 に戻す (Android)
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
| public class TestAdapter extends ArrayAdapter<BindData> { | |
| private LayoutInflater inflater; | |
| private ColorStateList defaultColorStateList = null; | |
| public TestAdapter(Context context, List<BindData> dataList) { | |
| super(context, 0, dataList); | |
| inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
| } | |
| public View getView(final int position, View convertView, ViewGroup parent) { | |
| final ViewHolder holder; | |
| if (convertView == null) { | |
| convertView = inflater.inflate(R.layout.inflate_list_item, null); | |
| holder = new ViewHolder(); | |
| // default色を保持 | |
| holder.text = (TextView) convertView.findViewById(R.id.text); | |
| defaultColorStateList = holder.text.getTextColors(); | |
| convertView.setTag(holder); | |
| } else { | |
| holder = (ViewHolder) convertView.getTag(); | |
| } | |
| if (!isEmpty()) { | |
| bindData(holder, getItem(position)); | |
| } | |
| return convertView; | |
| } | |
| private void bindData(ViewHolder holder, BindData data) { | |
| if (条件) { | |
| // custom | |
| holder.text.setTextColor(Color.RED); | |
| } else { | |
| // default | |
| holder.text.setTextColor(defaultColorStateList); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment