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.laquysoft.bycon.GoogleCardsActivity.java

public void postOrder(View w) {
    Log.i("ListActivity", "Post Order");
    new OrderTask().execute();

    // custom dialog
    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.payment_dialog);
    dialog.setTitle("Place & Pay Order");

    // set the custom dialog components - text, image and button
    ImageView image = (ImageView) dialog.findViewById(R.id.image);
    image.setImageResource(R.drawable.ic_launcher);

    Button dialogButton = (Button) dialog.findViewById(R.id.btn_accept);
    // if button is clicked, close the custom dialog
    dialogButton.setOnClickListener(new View.OnClickListener() {
        @Override/* ww  w . j  a v a 2 s.com*/
        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    Button dialogCancelButton = (Button) dialog.findViewById(R.id.btn_reject);
    // if button is clicked, close the custom dialog
    dialogCancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    dialog.show();
}

From source file:com.example.anumbrella.viewpager.IconPagerIndicator.java

@Override
public void notifyDataSetChanged() {
    mIconsLayout.removeAllViews();//  ww w . ja  v a 2s .c o m
    IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter();
    //??
    int count = iconAdapter.getCount();
    for (int i = 0; i < count; i++) {
        //??XML
        ImageView imageView = new ImageView(getContext(), null, R.attr.vpiIconPagerIndicatorStyle);
        imageView.setImageResource(iconAdapter.getIconResId(i));
        //tab
        mIconsLayout.addView(imageView);
    }
    if (mSelectedTabIndex > count) {
        mSelectedTabIndex = count - 1;
    }
    setCurrentItem(mSelectedTabIndex);
    //
    requestLayout();
}

From source file:com.aokp.romcontrol.github.tasks.DisplayProjectsListTask.java

protected void onPreExecute() {
    // start with a clean view, always
    mFavProjects.removeAll();/* w  w  w  .j a  va  2s.  co  m*/
    mCategory.removeAll();
    mPrefsList.removeAll(mPrefsList);
    mCategory.setTitle(mContext.getString(R.string.loading_projects));
    mCategory.setOrderingAsAdded(false);
    mFavPackagesStorage = new FavPackagesStorage();
    if (mFavPackagesStorage.getFavProjects().size() > 0) {
        mPreferenceScreen.addPreference(mFavProjects);
    } else {
        mPreferenceScreen.removePreference(mFavProjects);
    }
    if (mProgressDialog == null) {
        mProgressDialog = new ProgressDialog(mAlertDialog.getContext());
        ImageView imageView = new ImageView(mContext);
        imageView.setImageResource(R.drawable.octacat);
        mProgressDialog.show();
        mProgressDialog.setContentView(R.layout.github_octacat);
    }
}

From source file:com.owncloud.android.ui.fragment.ShareFileFragment.java

/**
 * {@inheritDoc}//from www  . j  a v  a 2 s.  c  o m
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.share_file_layout, container, false);

    // Setup layout
    // Image
    ImageView icon = (ImageView) view.findViewById(R.id.shareFileIcon);
    icon.setImageResource(MimetypeIconUtil.getFileTypeIconId(mFile.getMimetype(), mFile.getFileName()));
    if (mFile.isImage()) {
        String remoteId = String.valueOf(mFile.getRemoteId());
        Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(remoteId);
        if (thumbnail != null) {
            icon.setImageBitmap(thumbnail);
        }
    }
    // Name
    TextView filename = (TextView) view.findViewById(R.id.shareFileName);
    filename.setText(mFile.getFileName());
    // Size
    TextView size = (TextView) view.findViewById(R.id.shareFileSize);
    if (mFile.isFolder()) {
        size.setVisibility(View.GONE);
    } else {
        size.setText(DisplayUtils.bytesToHumanReadable(mFile.getFileLength()));
    }

    //  Add User Button
    Button addUserGroupButton = (Button) view.findViewById(R.id.addUserButton);
    addUserGroupButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean shareWithUsersEnable = AccountUtils.hasSearchUsersSupport(mAccount);
            if (shareWithUsersEnable) {
                // Show Search Fragment
                mListener.showSearchUsersAndGroups();
            } else {
                String message = getString(R.string.share_sharee_unavailable);
                Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
            }
        }
    });

    return view;
}

From source file:co.mike.apptemplate.Utils.ServerUtils.RESTCient.java

public static void loadWebImage(final ImageView imgNetwork, String URL, Context context) {
    //final String URL = "http://i.imgur.com/LrwApXg.png";

    // Using Picasso...
    //Picasso.with(this).load(URL).placeholder(R.drawable.default_avatar).error(R.drawable.grumpy_cat).transform(new PicassoRoundTransform()).into(imgNetwork);

    // Using Glide...
    //Glide.with(this).load(URL).placeholder(R.drawable.default_avatar).error(R.drawable.grumpy_cat).into(imgNetwork);

    // Using ION...
    Ion.with(context).load(URL)/*from ww w.  j a v  a  2s.  c o  m*/

            .asBitmap()

            .setCallback(new FutureCallback<Bitmap>() {
                @Override
                public void onCompleted(Exception e, Bitmap result) {
                    if (e == null) {
                        // Success
                        imgNetwork.setImageBitmap(result);
                    } else {
                        Log.e(TAG, "error downnload CAR URL");
                        imgNetwork.setImageResource(R.drawable.ic_launcher);
                    }
                }
            });
}

From source file:com.carver.paul.truesight.Ui.CounterPicker.CounterPickerFragment.java

protected void showHeadings(List<Integer> enemyImages) {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View headerView = inflater.inflate(R.layout.item_counter_picker_header, mCountersLinearLayout, false);

    for (int i = 0; i < enemyImages.size(); i++) {
        ImageView imageView = (ImageView) headerView.findViewById(headingImageViewIds.get(i));
        imageView.setImageResource(enemyImages.get(i));
    }/* www .  ja v a 2 s.c  o  m*/

    mCountersLinearLayout.addView(headerView);
}

From source file:com.hufeiya.SignIn.adapter.CategoryAdapter.java

private void setCategoryIcon(Category category, ImageView icon) {
    final int categoryImageResource = mResources.getIdentifier(ICON_CATEGORY + category.getId(), DRAWABLE,
            mPackageName);/*from   w w  w.jav  a  2s .c  o m*/
    icon.setImageResource(categoryImageResource);

}

From source file:com.birdgang.viewpagerheader.indicator.SpringIndicator.java

private void addTabItems() {
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.leftMargin = 30;//w  ww .  j a v  a 2 s.c om
    layoutParams.rightMargin = 30;

    tabs = new ArrayList<>();

    for (int i = 0; i < viewPager.getAdapter().getCount(); i++) {
        ImageView imageView = new ImageView(getContext());
        imageView.setImageResource(R.drawable.btn_pop_normal);
        imageView.setLayoutParams(layoutParams);
        final int position = i;
        imageView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (tabClickListener == null || tabClickListener.onTabClick(position)) {
                    viewPager.setCurrentItem(position);
                }
            }
        });

        tabs.add(imageView);
        tabContainer.addView(imageView);
    }
}

From source file:at.wada811.android.dialogfragments.sample.alertdialogfragment.AlertDialogFragmentExamplesFragment.java

@Override
public DialogFragmentCallback getDialogFragmentCallback() {
    return new SimpleDialogFragmentCallback() {
        @Override/*  ww w  .  j  ava  2s. co m*/
        public void onShow(DialogFragmentInterface dialog) {
            String text = "onShow";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel(DialogFragmentInterface dialog) {
            String text = "onCancel";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onDismiss(DialogFragmentInterface dialog) {
            String text = "onDismiss";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onClickPositive(DialogFragmentInterface dialog) {
            String text = "onClickPositive";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onClickNeutral(DialogFragmentInterface dialog) {
            String text = "onClickNeutral";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onClickNegative(DialogFragmentInterface dialog) {
            String text = "onClickNegative";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public boolean onKey(DialogFragmentInterface dialog, int keyCode, KeyEvent event) {
            String text = "onKey[keyCode: " + keyCode + ", KeyEvent: " + event + "]";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
            return false;
        }

        @Override
        public void onItemClick(DialogFragmentInterface dialog, int position) {
            Bundle extra = dialog.getExtra();
            String[] items = extra.getStringArray("items");
            String text = "onItemClick[position: " + position + ", item: " + items[position] + "]";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public ListAdapter getAdapter(DialogFragmentInterface dialog) {
            String[] items = new String[] { AlertDialog.class.getSimpleName(),
                    CharacterPickerDialog.class.getSimpleName(), ProgressDialog.class.getSimpleName(),
                    DatePickerDialog.class.getSimpleName(), TimePickerDialog.class.getSimpleName(), };
            Bundle extra = new Bundle();
            extra.putStringArray("items", items);
            dialog.setExtra(extra);
            return new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, items);
        }

        @Override
        public void onSingleChoiceClick(DialogFragmentInterface dialog, int position) {
            Bundle extra = dialog.getExtra();
            String[] items = extra.getStringArray("items");
            String text = "onItemClick[position: " + position + ", item: " + items[position] + "]";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onMultiChoiceClick(DialogFragmentInterface dialog, int position, boolean isChecked) {
            Bundle extra = dialog.getExtra();
            String[] items = extra.getStringArray("items");
            String text = "onItemClick[position: " + position + ", item: " + items[position] + ", isChecked: "
                    + isChecked + "]";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public View getCustomTitle(DialogFragmentInterface dialog) {
            TextView titleView = new TextView(getActivity());
            titleView.setText(dialog.getTag());
            titleView.setPadding(0, 24, 0, 24);
            titleView.setGravity(Gravity.CENTER);
            titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
            return titleView;
        }

        @Override
        public View getView(DialogFragmentInterface dialog) {
            ImageView imageView = new ImageView(getActivity());
            imageView.setImageResource(R.drawable.ic_launcher);
            imageView.setPadding(0, 24, 0, 24);
            return imageView;
        }
    };
}

From source file:com.dev.foundingfourfathers.alchemy.BrowseCocktails.DetailFragment.java

/**
 * Bind the views inside of parent with the fragment arguments.
 *
 * @param parent The parent of views to bind.
 *///  ww  w  .  j  a  v  a 2  s  .  c o  m
private void bind(View parent) {
    Bundle args = getArguments();
    if (args == null) {
        return;
    }
    ImageView image = (ImageView) parent.findViewById(R.id.image);
    image.setImageResource(args.getInt(ARG_RESOURCE_ID));
    TextView title = (TextView) parent.findViewById(R.id.title);
    title.setText(args.getString(ARG_TITLE));
}