Example usage for android.widget ImageView setImageResource

List of usage examples for android.widget ImageView setImageResource

Introduction

In this page you can find the example usage for android.widget ImageView setImageResource.

Prototype

@android.view.RemotableViewMethod(asyncImpl = "setImageResourceAsync")
public void setImageResource(@DrawableRes int resId) 

Source Link

Document

Sets a drawable as the content of this ImageView.

Usage

From source file:com.google.android.demos.jamendo.widget.SimpleFeedAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    for (int i = 0; i < mFrom.length; i++) {
        final View v = view.findViewById(mTo[i]);
        if (v != null) {
            int columnIndex = cursor.getColumnIndexOrThrow(mFrom[i]);
            if (!setViewValue(v, cursor, columnIndex)) {
                String value = cursor.getString(columnIndex);
                if (value == null) {
                    value = "";
                }/*from ww w .j  a  v a2 s  . co  m*/
                if (v instanceof TextView) {
                    TextView textView = (TextView) v;
                    textView.setText(value);
                } else if (v instanceof ImageView) {
                    ImageView imageView = (ImageView) v;
                    try {
                        imageView.setImageResource(Integer.parseInt(value));
                    } catch (NumberFormatException e) {
                        if (TextUtils.isEmpty(value)) {
                            value = mDefaultImageUrl;
                        }
                        mImageLoader.bind(this, imageView, value);
                    }
                } else {
                    throw new IllegalStateException(v.getClass().getName() + " is not a "
                            + " view that can be bound by this " + getClass().getSimpleName());
                }
            }
        }
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.MusicObj.java

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();/*  w ww.ja  va  2  s . c  om*/
    LinearLayout container = new LinearLayout(context);
    container.setLayoutParams(CommonLayouts.FULL_WIDTH);
    container.setOrientation(LinearLayout.HORIZONTAL);
    container.setGravity(Gravity.CENTER);

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.play);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    TextView valueTV = new TextView(context);
    valueTV.setText(asText(content));
    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.BOTTOM | Gravity.LEFT);
    valueTV.setPadding(4, 0, 0, 0);

    container.addView(imageView);
    container.addView(valueTV);
    frame.addView(container);
}

From source file:com.example.android.bangla.WordAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View listItemView = convertView;
    if (listItemView == null) {
        listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
    }/*from   w w  w .j  av a2s  .  c o m*/

    Word currentWord = getItem(position);
    TextView banglaTextView = (TextView) listItemView.findViewById(R.id.bangla_text_view);
    banglaTextView.setText(currentWord.getMiwokTranslationId());

    TextView englishTextView = (TextView) listItemView.findViewById(R.id.default_text_view);
    englishTextView.setText(currentWord.getDefaultTranslationId());

    ImageView imageView = (ImageView) listItemView.findViewById(R.id.image);

    if (currentWord.hasImage()) {
        imageView.setImageResource(currentWord.getImageResourceId());
        imageView.setVisibility(View.VISIBLE);
    } else {
        imageView.setVisibility(View.GONE);
    }

    View textContainer = listItemView.findViewById(R.id.text_container);
    int color = ContextCompat.getColor(getContext(), bColorResourceId);
    textContainer.setBackgroundColor(color);

    return listItemView;
}

From source file:ca.shoaib.ping.PingDetailActivityFragment.java

private void setStatus(int errorCode, ImageView statusImage, TextView statusText) {

    switch (errorCode) {
    case PingTask.PING_ERROR_NOERROR:
        statusImage.setImageResource(R.drawable.ic_check_circle_black_48dp);
        statusText.setText("");
        break;/*www.j  a v  a 2  s .c o  m*/
    case PingTask.PING_ERROR_NOTREACHABLE:
    default:
        statusImage.setImageResource(R.drawable.ic_error_outline_black_48dp);
        statusText.setText("Ping failed");
        break;
    }
}

From source file:com.alex.view.loop.BannerPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View view = LayoutInflater.from(mContext).inflate(R.layout.banner_item, container, false);
    ImageView imageView = (ImageView) view.findViewById(R.id.iv_banner_item);
    // ???//from  w w w .ja  va  2 s .  c o  m
    position %= pictureList.size();
    imageView.setImageResource(pictureList.get(position));
    container.addView(view);
    return view;
}

From source file:com.gammalabs.wifianalyzer.wifi.AccessPointDetail.java

private void setViewExtra(@NonNull Context context, @NonNull View view, @NonNull WiFiDetail wiFiDetail) {
    ImageView configuredImage = (ImageView) view.findViewById(R.id.configuredImage);
    WiFiAdditional wiFiAdditional = wiFiDetail.getWiFiAdditional();
    if (wiFiAdditional.isConfiguredNetwork()) {
        configuredImage.setVisibility(View.VISIBLE);
        configuredImage.setColorFilter(ContextCompat.getColor(context, R.color.connected));
    } else {//www . j  a v a 2  s  . c  om
        configuredImage.setVisibility(View.GONE);
    }

    WiFiSignal wiFiSignal = wiFiDetail.getWiFiSignal();
    Strength strength = wiFiSignal.getStrength();
    ImageView imageView = (ImageView) view.findViewById(R.id.levelImage);
    imageView.setImageResource(strength.imageResource());
    imageView.setColorFilter(ContextCompat.getColor(context, strength.colorResource()));

    ((TextView) view.findViewById(R.id.channel_frequency_range))
            .setText(wiFiSignal.getFrequencyStart() + " - " + wiFiSignal.getFrequencyEnd());
    ((TextView) view.findViewById(R.id.width))
            .setText("(" + wiFiSignal.getWiFiWidth().getFrequencyWidth() + WiFiSignal.FREQUENCY_UNITS + ")");
    ((TextView) view.findViewById(R.id.capabilities)).setText(wiFiDetail.getCapabilities());
}

From source file:com.example.jacob_ke.myapplication.Fragment_Content.java

public void updateContentView(int position) {
    Log.v(TAG, "updateArticleView");
    TextView article = (TextView) getActivity().findViewById(R.id.article);
    article.setText(Fragment_Array.Articles[position]);
    Button button = (Button) getActivity().findViewById(R.id.demo);
    button.setOnClickListener(new View.OnClickListener() {
        @Override//from  w w  w . ja  v  a2s.co  m
        public void onClick(View view) {
            Intent intent = new Intent(getActivity(), DisplayMessageActivity_1.class);
            startActivity(intent);
        }
    });
    ImageView img = (ImageView) getActivity().findViewById(R.id.img);
    img.setImageResource(R.drawable.unweb);
    if (position == 0) {

        button.setVisibility(View.VISIBLE);
        img.setVisibility(View.INVISIBLE);
    } else {
        button.setVisibility(View.INVISIBLE);
        img.setVisibility(View.VISIBLE);
    }
    mCurrentPosition = position;
}

From source file:com.moxm.frameworks.support.indicator.IconPageIndicator.java

public void notifyDataSetChanged() {
    mIconsLayout.removeAllViews();//from   ww w  .j a  va  2 s .c o  m
    IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter();
    int count = iconAdapter.getCount();
    for (int i = 0; i < count; i++) {
        ImageView view = new ImageView(getContext(), null, 0);
        view.setImageResource(iconAdapter.getIconResId(i));
        view.setPadding(3, 0, 3, 0);
        mIconsLayout.addView(view);
    }
    if (mSelectedIndex > count) {
        mSelectedIndex = count - 1;
    }
    setCurrentItem(mSelectedIndex);
    requestLayout();
}

From source file:ca.liquidlabs.android.speedtestvisualizer.fragments.SpeedTestInfoWindowAdapter.java

/**
 * Renders marker contents into the infobox
 * //from w  ww .  j  a  va2s .  c  om
 * @param marker Map marker
 * @param view Custom infobox view
 */
private void renderContents(Marker marker, View view) {
    String[] snippetInfo = StringUtils.split(marker.getSnippet(), AppConstants.TEXT_SEPARATOR);

    TextView infoHeading = (TextView) view.findViewById(R.id.txt_info_heading);
    infoHeading.setText("@ " + marker.getTitle());

    TextView downloadSpeed = (TextView) view.findViewById(R.id.txt_info_download);
    downloadSpeed.setText(snippetInfo[1]);

    TextView uploadSpeed = (TextView) view.findViewById(R.id.txt_info_upload);
    uploadSpeed.setText(snippetInfo[2]);

    // Connection type - update image based on type
    ConnectionType connType = ConnectionType.fromString(snippetInfo[0]);
    ImageView conntypeImage = (ImageView) view.findViewById(R.id.img_legend_conntype);
    if (connType.isWifi()) {
        conntypeImage.setImageResource(R.drawable.ic_connection_wifi);
    } else {
        conntypeImage.setImageResource(R.drawable.ic_connection_cell);
    }
    TextView connTypeTxt = (TextView) view.findViewById(R.id.txt_info_conntype);
    connTypeTxt.setText(snippetInfo[0]);
}

From source file:com.aqnote.app.wifianalyzer.wifi.AccessPointsDetail.java

void setView(@NonNull Resources resources, @NonNull View view, @NonNull WiFiDetail wiFiDetail,
        boolean isChild) {
    TextView textSSID = (TextView) view.findViewById(R.id.ssid);

    textSSID.setText(wiFiDetail.getTitle());

    view.findViewById(R.id.ipAddress).setVisibility(View.GONE);
    view.findViewById(R.id.linkSpeed).setVisibility(View.GONE);

    ImageView configuredImage = (ImageView) view.findViewById(R.id.configuredImage);
    WiFiAdditional wiFiAdditional = wiFiDetail.getWiFiAdditional();
    if (wiFiAdditional.isConfiguredNetwork()) {
        configuredImage.setVisibility(View.VISIBLE);
        configuredImage.setColorFilter(resources.getColor(R.color.connected));
    } else {/*from  w ww.j  a v  a2 s  . c  om*/
        configuredImage.setVisibility(View.GONE);
    }

    WiFiSignal wiFiSignal = wiFiDetail.getWiFiSignal();
    Strength strength = wiFiSignal.getStrength();
    ImageView imageView = (ImageView) view.findViewById(R.id.levelImage);
    imageView.setImageResource(strength.imageResource());
    imageView.setColorFilter(resources.getColor(strength.colorResource()));

    Security security = wiFiDetail.getSecurity();
    ImageView securityImage = (ImageView) view.findViewById(R.id.securityImage);
    securityImage.setImageResource(security.imageResource());
    securityImage.setColorFilter(resources.getColor(R.color.icons_color));

    TextView textLevel = (TextView) view.findViewById(R.id.level);
    textLevel.setText(wiFiSignal.getLevel() + "dBm");
    textLevel.setTextColor(resources.getColor(strength.colorResource()));

    ((TextView) view.findViewById(R.id.channel)).setText(wiFiSignal.getChannelDisplay());
    ((TextView) view.findViewById(R.id.primaryFrequency))
            .setText(wiFiSignal.getPrimaryFrequency() + WifiInfo.FREQUENCY_UNITS);
    ((TextView) view.findViewById(R.id.distance)).setText(String.format("%.1fm", wiFiSignal.getDistance()));
    ((TextView) view.findViewById(R.id.channel_frequency_range))
            .setText(wiFiSignal.getFrequencyStart() + " - " + wiFiSignal.getFrequencyEnd());
    ((TextView) view.findViewById(R.id.width))
            .setText("(" + wiFiSignal.getWiFiWidth().getFrequencyWidth() + WifiInfo.FREQUENCY_UNITS + ")");
    ((TextView) view.findViewById(R.id.capabilities)).setText(wiFiDetail.getCapabilities());

    TextView textVendor = ((TextView) view.findViewById(R.id.vendor));
    String vendor = wiFiAdditional.getVendorName();
    if (StringUtils.isBlank(vendor)) {
        textVendor.setVisibility(View.GONE);
    } else {
        textVendor.setVisibility(View.VISIBLE);
        textVendor.setText(vendor.substring(0, Math.min(VENDOR_NAME_MAX, vendor.length())));
    }

    if (isChild) {
        view.findViewById(R.id.tab).setVisibility(View.VISIBLE);
    } else {
        view.findViewById(R.id.tab).setVisibility(View.GONE);
    }

}