Java Code Examples for android.widget.ImageView.setImageState()

The following are Jave code examples for showing how to use setImageState() of the android.widget.ImageView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: SetupWizardLibCompat   File: Item.java   View Source Code Vote up 7 votes
@Override
public void onBindView(View view) {
    TextView label = (TextView) view.findViewById(R.id.suw_items_title);
    label.setText(getTitle());

    TextView summaryView = (TextView) view.findViewById(R.id.suw_items_summary);
    CharSequence summary = getSummary();
    if (summary != null && summary.length() > 0) {
        summaryView.setText(summary);
        summaryView.setVisibility(View.VISIBLE);
    } else {
        summaryView.setVisibility(View.GONE);
    }

    final View iconContainer = view.findViewById(R.id.suw_items_icon_container);
    final Drawable icon = getIcon();
    if (icon != null) {
        final ImageView iconView = (ImageView) view.findViewById(R.id.suw_items_icon);
        // Set the image drawable to null before setting the state and level to avoid affecting
        // any recycled drawable in the ImageView
        iconView.setImageDrawable(null);
        iconView.setImageState(icon.getState(), false /* merge */);
        iconView.setImageLevel(icon.getLevel());
        iconView.setImageDrawable(icon);
        iconContainer.setVisibility(View.VISIBLE);
    } else {
        iconContainer.setVisibility(View.GONE);
    }

    view.setId(getViewId());
}