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.normalexception.app.rx8club.handler.AvatarLoader.java

/**
 * Once we get the image, we actually want to display it
 * @param url      The url of the image//  ww  w. j  ava 2s. c  o  m
 * @param imageView   The view to put the image in
 */
public void DisplayImage(String url, ImageView imageView) {
    imageViews.put(imageView, url);
    Bitmap bitmap = memoryCache.get(url);
    if (bitmap != null)
        imageView.setImageBitmap(bitmap);
    else {
        queuePhoto(url, imageView);
        imageView.setImageResource(stub_id);
    }
}

From source file:com.klinker.android.theme_spotlight.activity.SpotlightActivity.java

private void hackSearchView() {
    // hack to change the search actionbar icon from that crappy low res default
    int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
    ImageView view = (ImageView) mSearchView.findViewById(searchImgId);
    view.setImageResource(R.drawable.ic_action_search);

    // hack to change the magnifying glass low res image
    searchImgId = getResources().getIdentifier("android:id/search_mag_icon", null, null);
    view = (ImageView) mSearchView.findViewById(searchImgId);
    view.setImageResource(R.drawable.ic_action_search);

    // hack to change the close button low res image
    searchImgId = getResources().getIdentifier("android:id/search_close_btn", null, null);
    view = (ImageView) mSearchView.findViewById(searchImgId);
    view.setImageResource(R.drawable.ic_action_cancel);

    // hack to change the search edit text background to white
    int searchEditTextId = getResources().getIdentifier("android:id/search_plate", null, null);
    View autoCompleteView = mSearchView.findViewById(searchEditTextId);
    autoCompleteView.setBackgroundResource(R.drawable.searchview_textfield_activated_holo_light);
}

From source file:com.nextgis.mobile.MapFragment.java

protected void addMapButtons(RelativeLayout rl) {
    mivZoomIn = new ImageView(getActivity());
    mivZoomIn.setImageResource(R.drawable.ic_plus);
    //mivZoomIn.setId(R.drawable.ic_plus);

    mivZoomOut = new ImageView(getActivity());
    mivZoomOut.setImageResource(R.drawable.ic_minus);
    //mivZoomOut.setId(R.drawable.ic_minus);

    final ImageView ivMark = new ImageView(getActivity());
    ivMark.setImageResource(R.drawable.ic_mark);
    //ivMark.setId(R.drawable.ic_mark);

    //show zoom level between plus and minus
    mivZoomLevel = new TextView(getActivity());
    //ivZoomLevel.setAlpha(150);
    mivZoomLevel.setId(R.drawable.ic_zoomlevel);

    final float scale = getResources().getDisplayMetrics().density;
    int pixels = (int) (48 * scale + 0.5f);

    mivZoomLevel.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
    //ivZoomLevel.setTextAppearance(this, android.R.attr.textAppearanceLarge);

    mivZoomLevel.setWidth(pixels);/* ww w.j  a v  a 2 s. c o m*/
    mivZoomLevel.setHeight(pixels);
    mivZoomLevel.setTextColor(Color.DKGRAY);
    mivZoomLevel.setBackgroundColor(Color.argb(50, 128, 128, 128)); //Color.LTGRAY R.drawable.ic_zoomlevel);
    mivZoomLevel.setGravity(Gravity.CENTER);
    mivZoomLevel.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    mivZoomLevel.setText("" + (int) Math.floor(mMap.getZoomLevel()));

    mivZoomIn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mMap.zoomIn();
        }
    });

    mivZoomOut.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mMap.zoomOut();
        }
    });

    ivMark.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            //TODO: onMark();
        }
    });

    final RelativeLayout.LayoutParams RightParams1 = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RightParams1.setMargins(mMargings + 5, mMargings - 5, mMargings + 5, mMargings - 5);
    RightParams1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    RightParams1.addRule(RelativeLayout.CENTER_IN_PARENT);//ALIGN_PARENT_TOP
    rl.addView(mivZoomLevel, RightParams1);

    final RelativeLayout.LayoutParams RightParams4 = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RightParams4.setMargins(mMargings + 5, mMargings - 5, mMargings + 5, mMargings - 5);
    RightParams4.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    RightParams4.addRule(RelativeLayout.ABOVE, R.drawable.ic_zoomlevel);//ALIGN_PARENT_TOP
    rl.addView(mivZoomIn, RightParams4);

    final RelativeLayout.LayoutParams RightParams3 = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RightParams3.setMargins(mMargings + 5, mMargings - 5, mMargings + 5, mMargings - 5);
    RightParams3.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    RightParams3.addRule(RelativeLayout.CENTER_IN_PARENT);//ALIGN_PARENT_TOP
    rl.addView(ivMark, RightParams3);

    final RelativeLayout.LayoutParams RightParams2 = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RightParams2.setMargins(mMargings + 5, mMargings - 5, mMargings + 5, mMargings - 5);
    RightParams2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    RightParams2.addRule(RelativeLayout.BELOW, R.drawable.ic_zoomlevel);//R.drawable.ic_plus);
    rl.addView(mivZoomOut, RightParams2);

    setZoomInEnabled(mMap.canZoomIn());
    setZoomOutEnabled(mMap.canZoomOut());
}

From source file:baasi.hackathon.sja.TalkActivity.java

/**
 * ???? ? ?//from   w w w.jav a2 s. c om
 * @param resId
 */
private void addToContainer(int resId) {

    if (containerLayout != null && containerLayout.getChildCount() <= 4) {

        ImageView image = new ImageView(getBaseContext());
        image.setImageResource(resId);
        LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(170, 170);

        image.setLayoutParams(parms);
        image.setScaleType(ImageView.ScaleType.CENTER_CROP);

        PlayAnim(image, this, R.anim.slide_right_in, 0);

        image.setTag(resId);
        containerLayout.addView(image);

    }
}

From source file:com.bexkat.feedlib.ItemListFragment.java

@Override
public void onActivityCreated(Bundle saveInstanceState) {
    String[] from = new String[] { ItemTable.COLUMN_TITLE, ItemTable.COLUMN_PUBDATE, ItemTable.COLUMN_READ,
            ItemTable.COLUMN_FAVORITE };
    int[] to = new int[] { R.id.row_title, R.id.row_pubdate, R.id.row_status, R.id.row_status };

    super.onActivityCreated(saveInstanceState);

    getListView().setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override/*from   ww  w.java2  s.  co m*/
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            if (mActionMode != null) {
                return false;
            }
            ItemTable db = new ItemTable(getSherlockActivity());
            selectedItem = db.getItem(id);
            // Start the CAB using the ActionMode.Callback defined above
            mActionMode = getSherlockActivity().startActionMode(mActionModeCallback);
            view.setSelected(true);
            return true;
        }
    });

    mCursorAdapter = new SimpleCursorAdapter(getActivity(), R.layout.item_list, null, from, to,
            SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    mCursorAdapter.setViewBinder(new ViewBinder() {

        @Override
        public boolean setViewValue(View v, Cursor c, int index) {
            if (index == c.getColumnIndex(ItemTable.COLUMN_READ)) {
                ImageView iv = (ImageView) v;
                if (c.getInt(index) == DatabaseHelper.OFF)
                    iv.setImageResource(R.drawable.unread);
                return true;
            }
            if (index == c.getColumnIndex(ItemTable.COLUMN_PUBDATE)) {
                String date = mFormat.format(new Date(Long.parseLong(c.getString(index))));
                ((TextView) v).setText(date);
                return true;
            }
            if (index == c.getColumnIndex(ItemTable.COLUMN_FAVORITE)) {
                ImageView iv = (ImageView) v;
                if (c.getInt(index) == DatabaseHelper.ON)
                    iv.setImageResource(R.drawable.ic_favorite);
                if (c.getInt(c.getColumnIndex(ItemTable.COLUMN_READ)) == DatabaseHelper.ON
                        && c.getInt(index) == DatabaseHelper.OFF)
                    iv.setVisibility(View.INVISIBLE);
                else
                    iv.setVisibility(View.VISIBLE);
                return true;
            }
            return false;
        }

    });
    setListAdapter(mCursorAdapter);
    getLoaderManager().initLoader(0, null, this);
}

From source file:com.coodesoft.notee.DataAdapter.java

public View getView(int position, View convertView, ViewGroup parent) {
    boolean isLastRow = position >= m_nItemsLoaded;
    int rowResID = isLastRow ? loadingRowResID : itemRowResID;
    LayoutInflater inflater = LayoutInflater.from(context);
    View v = inflater.inflate(rowResID, parent, false);
    if (isLastRow) {
        if (position < m_nNoteAmount) {
            // Should there be more items loaded?
            int nextItemToLoad = position + PRELOAD_ITEMS;
            if (nextItemToLoad > m_nNoteAmount)
                nextItemToLoad = m_nNoteAmount;
            Log.d(LOG_TAG, "nextItemToLoad: " + nextItemToLoad);
            if (nextItemToLoad > m_nItemsLoaded) {
                Log.d(LOG_TAG, "itemsToLoad: " + nextItemToLoad);
                // Launch the loading thread if it is not currently running
                synchronized (loading) {
                    if (!loading.booleanValue()) {
                        Log.d(LOG_TAG, "Staring loading task");
                        loading = Boolean.TRUE;
                        m_threadLoading = new LoadingThread();
                        m_threadLoading.start();
                        Log.d(LOG_TAG, "Loading task started");
                    }/*  www .jav  a  2 s .  c om*/
                }
            }
        } else
            uiHandler.post(updateTask);
    } else {
        synchronized (m_lstNoteItems) {
            NoteItem item = m_lstNoteItems.get(position);
            // title
            TextView itemControl = (TextView) v.findViewById(R.id.note_item_title);
            itemControl.setText(item.m_strTitle);

            // set at
            TextView itemDate = (TextView) v.findViewById(R.id.note_item_subtitle);
            itemDate.setText(item.getSetAt());

            // icon
            ImageView imageView = (ImageView) v.findViewById(R.id.image_view_icon);
            if (item.isNote())
                imageView.setImageResource(R.drawable.ic_note);
            else
                imageView.setImageResource(R.drawable.ic_schedule);
        }
    }
    return v;
}

From source file:com.sunho.nating.fragments.DetailUnivFragment.java

private void bindFragment(View parent) {
    Bundle args = getArguments();//www  .j  a va 2  s .co m
    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));
    listView = (ListView) parent.findViewById(R.id.list);
    listView.setDividerHeight(0);
    adapter = new CustomListAdapter(MainActivity.mActivity, placeList) {
        @Override
        public View getDataRow(int position, View convertView, ViewGroup parent) {
            return convertView;
        }
    };
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(MainActivity.mContext, placeList.get(position).getOldAddress(), 0).show();
            moveFragment(position);
        }
    });
    listView.setOnScrollListener(new EndlessScrollListener() {
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            super.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
            //lastListitem = (totalItemCount - 1 > 0) && (firstVisibleItem + visibleItemCount >= totalItemCount - 1);
        }

        @Override
        public void onLoadMore(int page, int totalItemsCount) {
            // Triggered only when new data needs to be appended to the list
            // Add whatever code is needed to append new items to your AdapterView

            Log.d(TAG, "==ListView Information==");
            Log.d(TAG, "PageNumber : " + page);
            Log.d(TAG, "TotalCount : " + totalItemsCount);
            Log.d(TAG, "adpaterCount : " + adapter.getCount());
            Log.d(TAG, "========================");
            new GetDataTask().execute();

        }
    });
    new GetDataTask().execute();
}

From source file:com.example.pyrkesa.frag.ScenarioAdapter.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.scenario_list_item, null);
    }//from  w ww  . ja  v a 2  s  .  c o  m
    pos = position;
    ImageView imgIcon = (ImageView) convertView.findViewById(R.id.scenario);
    final TextView txtTitle = (TextView) convertView.findViewById(R.id.scenario_name);
    ImageButton imgDelete = (ImageButton) convertView.findViewById(R.id.delete_scenario);

    imgIcon.setImageResource(scenarioItems.get(position).getIcon_Scenario());
    txtTitle.setText(scenarioItems.get(position).getName());
    imgDelete.setImageResource(scenarioItems.get(position).getIcon_Delete());
    imgDelete.setOnClickListener(new View.OnClickListener() {

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

            ModelFactory model = (ModelFactory) ModelFactory.getContext();

            new AlertDialog.Builder(v.getContext()).setTitle("Supprimer " + txtTitle.getText())
                    .setMessage("Voulez-vous supprimer ce scnario?")
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            // continue with delete
                            new DeleteScenario().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();
        }
    });

    return convertView;
}

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

@Override
public void refresh() {
    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);
        // Check if at least a topic is subscribed for this sender
        int subscribedTopics = 0;
        for (Boolean subscribed : sender.topics.values()) {
            if (subscribed) {
                subscribedTopics++;/*from   w ww .j  ava 2 s. c  o m*/
            }
        }
        if (subscribedTopics > 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 (Map.Entry<String, Boolean> topic : sender.topics.entrySet()) {
                if (topic.getValue()) {
                    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.bigtop_updates_grey600);
                    label.setText(topic.getKey());
                    button.setText(R.string.topics_unsubscribe);
                    button.setTag(R.id.tag_action, ACTION_UNSUBSCRIBE);
                    button.setTag(R.id.tag_senderid, sender.senderId);
                    button.setTag(R.id.tag_topic, topic.getKey());
                    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.topics_no_topic_subscribed));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout topicsView = (FrameLayout) getActivity().findViewById(R.id.topics_list_wrapper);
    topicsView.removeAllViews();
    topicsView.addView(sendersList);
}

From source file:cn.bingoogolapple.androidcommon.adapter.BGAViewHolderHelper.java

/**
 * @param viewId/*from ww  w  .ja  v a2s . c o  m*/
 * @param imageResId ??id
 * @return
 */
public BGAViewHolderHelper setImageResource(@IdRes int viewId, @DrawableRes int imageResId) {
    ImageView view = getView(viewId);
    view.setImageResource(imageResId);
    return this;
}