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.example.pyrkesa.frag.UserAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater mInflater = (LayoutInflater) context1.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        convertView = mInflater.inflate(R.layout.user_list_item, null);
    }/*from w  ww .  j  a va  2 s  . c  o  m*/
    pos = position;
    ImageView imgIcon = (ImageView) convertView.findViewById(R.id.contact);
    final TextView txtTitle = (TextView) convertView.findViewById(R.id.user_login);
    ImageButton imgDelete = (ImageButton) convertView.findViewById(R.id.delete);

    imgIcon.setImageResource(userItems.get(position).getIcon());
    txtTitle.setText(userItems.get(position).getTitle());
    imgDelete.setImageResource(userItems.get(position).getDelete());

    imgDelete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //Toast.makeText(context1,"ggffgfg",Toast.LENGTH_LONG).show();

            ModelFactory model = (ModelFactory) ModelFactory.getContext();
            if (model.user.type == 1) {
                new AlertDialog.Builder(v.getContext()).setTitle("Supprimer " + txtTitle.getText())
                        .setMessage("Voulez-vous supprimer cet utilisateur?")
                        .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                // continue with delete
                                new DeleteUser().execute(txtTitle.getText().toString());
                            }
                        }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                // do nothing
                            }
                        }).setIcon(android.R.drawable.ic_dialog_alert).show();
            } else {
                new AlertDialog.Builder(v.getContext()).setTitle("Attention")
                        .setMessage("Opration interdite : Droits d'administration requis.").show();
            }

        }
    });

    return convertView;
}

From source file:com.sutromedia.android.core.PhotoActivity.java

public void onStartSlideShow(View view) {
    ImageView image = (ImageView) view;
    image.setImageResource(R.drawable.pause_button);
    doStartSlideShow(SLIDESHOW_START_DELAY_MEDIUM);
}

From source file:com.mobeta.android.dslv.SimpleDragSortCursorAdapter.java

/**
 * Called by bindView() to set the image for an ImageView but only if there
 * is no existing ViewBinder or if the existing ViewBinder cannot handle
 * binding to an ImageView.//from   www . java  2 s  . c o  m
 *
 * By default, the value will be treated as an image resource. If the value
 * cannot be used as an image resource, the value is used as an image Uri.
 *
 * Intended to be overridden by Adapters that need to filter strings
 * retrieved from the database.
 *
 * @param v
 *            ImageView to receive an image
 * @param value
 *            the value retrieved from the cursor
 */
public void setViewImage(final ImageView v, final String value) {
    try {
        v.setImageResource(Integer.parseInt(value));
    } catch (final NumberFormatException nfe) {
        v.setImageURI(Uri.parse(value));
    }
}

From source file:com.mZone.epro.common.view.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;//  w w  w  .j ava 2  s  . com
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            TypedValue outValue = new TypedValue();
            getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
            tabView.setBackgroundResource(outValue.resourceId);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);

            if (mTabViewLayoutId == R.layout.launch_home_fragment_tabhost_tabwidget) {
                ImageView iconView = (ImageView) tabView.findViewById(R.id.tabwidget_imageview);
                iconView.setImageResource(mCustomTabDelegate.getIconId(i, 0));
            }
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);
        tabViewArray.add(tabView);
        mTabStrip.addView(tabView);
    }
}

From source file:com.google.android.gcm.demo.ui.InstanceIdFragment.java

@Override
public void refresh() {
    new AsyncTask<Void, Void, Void>() {
        @Override//from w ww.  j av a2  s  . c o m
        protected Void doInBackground(Void... params) {
            final String instanceId = mInstanceIdHelper.getInstanceId();
            final String creationTime = DateFormat.getDateTimeInstance()
                    .format(new Date(mInstanceIdHelper.getCreationTime()));
            final Activity activity = getActivity();
            if (activity != null) {
                Handler handler = new Handler(activity.getMainLooper());
                handler.post(new Runnable() {
                    public void run() {
                        setValue(activity.findViewById(R.id.iid_instance_id), instanceId);
                        setValue(activity.findViewById(R.id.iid_creation_time), creationTime);
                    }
                });
            }
            return null;
        }
    }.execute();
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> addressBook = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < addressBook.size(); i++) {
        Sender sender = addressBook.valueAt(i);
        if (sender.appTokens.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderLabel = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderLabel.setText(getString(R.string.topics_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (Token token : sender.appTokens.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.smartphone_grey600);
                label.setText(token.scope + " - " + AbstractFragment.truncateToMediumString(token.token));
                button.setText(R.string.iid_delete_token);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_scope, token.scope);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.iid_no_tokens));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout tokensView = (FrameLayout) getActivity().findViewById(R.id.iid_tokens_wrapper);
    tokensView.removeAllViews();
    tokensView.addView(sendersList);
}

From source file:com.chillax.viewpagerindicator.IconPageIndicator.java

public void notifyDataSetChanged() {
    mIconsLayout.removeAllViews();/*  ww w  .j  a v a 2 s  . c  om*/
    IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter();
    int count = iconAdapter.getCount();
    int padding = ScreenUtil.dp2px(context, 10);
    for (int i = 0; i < count; i++) {
        ImageView view = new ImageView(getContext());
        view.setLayoutParams(
                new ViewGroup.LayoutParams(ScreenUtil.dp2px(context, 35), ScreenUtil.dp2px(context, 35)));
        view.setPadding(padding, padding, padding, padding);
        view.setScaleType(ImageView.ScaleType.FIT_XY);
        view.setImageResource(R.drawable.leader_icon);
        mIconsLayout.addView(view);
    }
    if (mSelectedIndex > count) {
        mSelectedIndex = count - 1;
    }
    setCurrentItem(mSelectedIndex);
    requestLayout();
}

From source file:com.blandware.android.atleap.loader.ViewLoadable.java

/**
 * Called by bindView() to set the image for an ImageView but only if
 * there is no existing ViewBinder or if the existing ViewBinder cannot
 * handle binding to an ImageView./* w ww .  ja  va 2 s  . co m*/
 *
 * By default, the value will be treated as an image resource. If the
 * value cannot be used as an image resource, the value is used as an
 * image Uri.
 *
 * Intended to be overridden that need to filter strings
 * retrieved from the database.
 *
 * @param v ImageView to receive an image
 * @param value the value retrieved from the cursor
 */
public void setViewImage(ImageView v, String value) {
    try {
        v.setImageResource(Integer.parseInt(value));
    } catch (NumberFormatException nfe) {
        v.setImageURI(Uri.parse(value));
    }
}

From source file:com.abcvoipsip.ui.prefs.CodecsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    prefsWrapper = new PreferencesWrapper(getActivity());
    initDatas();/*from   ww  w. ja  v a  2 s .  c  o  m*/
    setHasOptionsMenu(true);

    // Adapter
    mAdapter = new SimpleAdapter(getActivity(), codecsList, R.layout.codecs_list_item,
            new String[] { CODEC_NAME, CODEC_PRIORITY }, new int[] { R.id.line1, R.id.entiere_line });

    mAdapter.setViewBinder(new ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object data, String textRepresentation) {
            if (view.getId() == R.id.entiere_line) {
                Log.d(THIS_FILE, "Entiere line is binded ");
                TextView tv = (TextView) view.findViewById(R.id.line1);
                ImageView grabber = (ImageView) view.findViewById(R.id.icon);
                if ((Short) data == 0) {
                    tv.setTextColor(Color.GRAY);
                    grabber.setImageResource(R.drawable.ic_mp_disabled);
                } else {
                    tv.setTextColor(Color.WHITE);
                    grabber.setImageResource(R.drawable.ic_mp_move);
                }
                return true;
            }
            return false;
        }

    });

    setListAdapter(mAdapter);
    registerForContextMenu(getListView());
}

From source file:com.klinker.android.twitter.activities.search.SearchPager.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.search_activity, menu);

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();

    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);

    int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
    ImageView view = (ImageView) searchView.findViewById(searchImgId);
    view.setImageResource(settings.theme == AppSettings.THEME_LIGHT ? R.drawable.ic_action_search_light
            : R.drawable.ic_action_search_dark);

    return true;//from w  w w.  j av a 2 s  . c  om
}

From source file:com.hao.common.adapter.BaseViewHolderHelper.java

/**
 * @param viewId//from www.j a v a2  s . c  om
 * @param imageResId ??id
 * @return
 */
public BaseViewHolderHelper setImageResource(@IdRes int viewId, @DrawableRes int imageResId) {
    ImageView view = getView(viewId);
    view.setImageResource(imageResId);
    return this;
}