Example usage for android.widget ImageView setBackgroundResource

List of usage examples for android.widget ImageView setBackgroundResource

Introduction

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

Prototype

@RemotableViewMethod
public void setBackgroundResource(@DrawableRes int resid) 

Source Link

Document

Set the background to a given resource.

Usage

From source file:mobisocial.musubi.objects.PictureObj.java

@Override
public View createView(Context context, ViewGroup parent) {
    LinearLayout frame = new LinearLayout(context);
    frame.setLayoutParams(CommonLayouts.FULL_WIDTH);
    frame.setOrientation(LinearLayout.VERTICAL);

    ImageView imageView = new ImageView(context);
    imageView.setBackgroundResource(android.R.drawable.picture_frame);
    imageView.setPadding(6, 4, 8, 9);/*  w w w  .j a v a 2s .c  o m*/
    frame.addView(imageView);

    TextView textView = new TextView(context);
    frame.addView(textView);

    return frame;
}

From source file:com.xiaoya.framepager.SuperAwesomeCardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    System.out.println(position + "======>>>>>");
    View v = inflater.inflate(R.layout.fragment_setting, container, false);

    FrameLayout fram_gallery = (FrameLayout) v.findViewById(R.id.frame_gallery);
    fram_gallery.setVisibility(View.GONE);
    ListView lv_news = (ListView) v.findViewById(R.id.lv_news);

    System.out.println("position  ====>>>>>>" + position);
    if (position == 0) {
        fram_gallery.setVisibility(View.VISIBLE);
        images_ga = (AdImageGallery) v.findViewById(R.id.image_wall_gallery);
        images_ga.setImageActivity(this);
        Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.gallary_moren);
        imagesCache.put("background_non_load", image); // 
        linear_point = (LinearLayout) v.findViewById(R.id.gallery_point_linear);

        urls = new ArrayList<String>(); // List
        urls.add("http://f11.topit.me/l/201009/16/12845672546160.jpg");
        urls.add("http://f12.topit.me/l166/101665601956b260eb.jpg");
        urls.add("http://i6.topit.me/6/15/50/1147943393d6950156l.jpg");
        urls.add("http://f6.topit.me/6/08/22/113361531058822086l.jpg");
        urls.add("http://i9.topit.me/9/23/10/1147966176c1910239l.jpg");

        List<String> imageList = new ArrayList<String>();
        imageList.add("");
        imageList.add("");
        imageList.add("");
        imageList.add("");
        imageList.add("");

        ImageAdapter imageAdapter = new ImageAdapter(getActivity(), urls, imageList);
        images_ga.setAdapter(imageAdapter);
        images_ga.setOnItemClickListener(new OnItemClickListener() {
            @Override/*from w w  w  .j  av a  2  s .co m*/
            public void onItemClick(AdapterView<?> arg0, View arg1, int positioin, long arg3) {
                // TODO Auto-generated method stub
                Toast.makeText(getActivity(), ":" + positioin + ":....",
                        Toast.LENGTH_SHORT).show();
            }
        });

        //         for (int i = 0; i < urls.size(); i++) {
        //            TextView textView=new TextView(getActivity());
        //            textView.setText(imageList.get(i%urls.size()));
        //            linear_point.addView(textView);
        //         }
        for (int i = 0; i < urls.size(); i++) {
            ImageView pointView = new ImageView(getActivity());
            if (i == 0) {
                pointView.setBackgroundResource(R.drawable.feature_point_cur);
            } else
                pointView.setBackgroundResource(R.drawable.feature_point);

            linear_point.addView(pointView);

        }

    }
    lv_news.setAdapter(new MyAdapter_news(getActivity(), list));
    return v;
}

From source file:com.jiujie8.choice.core.TabPagerActivity.java

/**
 * Create tab using information from current adapter
 * <p>//from   w ww  .j a v  a 2s .c o  m
 * This can be called when the tabs changed but must be called after an
 * initial call to {@link #configureTabPager()}
 */
protected void createTabs() {
    if (host.getTabWidget().getTabCount() > 0) {
        // Crash on Gingerbread if tab isn't set to zero since adding a
        // new tab removes selection state on the old tab which will be
        // null unless the current tab index is the same as the first
        // tab index being added
        host.setCurrentTab(0);
        host.clearAllTabs();
    }

    LayoutInflater inflater = getLayoutInflater();
    int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        TabSpec spec = host.newTabSpec("tab" + i);
        spec.setContent(this);
        View view = inflater.inflate(getTabIndicatorView(), null);
        ImageView imageView = (ImageView) view.findViewById(R.id.iv_icon);
        int tabIcon = getTabIcon(i);
        if (tabIcon != 0) {
            imageView.setBackgroundResource(tabIcon);
        } else {
            ViewUtils.setGone(imageView, true);
        }
        ((TextView) view.findViewById(R.id.tv_tab)).setText(getTitle(i));

        spec.setIndicator(view);
        host.addTab(spec);

        int background;
        if (i == 0)
            background = getLeftBackground();
        else if (i == count - 1)
            background = getCentreBackground();
        else
            background = getRightBackground();
        view.findViewById(R.id.rl_text).setBackgroundResource(background);
    }
}

From source file:com.shengzhish.xyj.core.TabPagerActivity.java

/**
 * Create tab using information from current adapter
 * <p>/*w  ww. ja v a 2  s . com*/
 * This can be called when the tabs changed but must be called after an
 * initial call to {@link #configureTabPager()}
 */
protected void createTabs() {
    if (host.getTabWidget().getTabCount() > 0) {
        // Crash on Gingerbread if tab isn't set to zero since adding a
        // new tab removes selection state on the old tab which will be
        // null unless the current tab index is the same as the first
        // tab index being added
        host.setCurrentTab(0);
        host.clearAllTabs();
    }

    LayoutInflater inflater = getLayoutInflater();
    int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        TabSpec spec = host.newTabSpec("tab" + i);
        spec.setContent(this);
        View view = inflater.inflate(R.layout.tab, null);
        ImageView imageView = (ImageView) view.findViewById(R.id.iv_icon);
        int tabIcon = getTabIcon(i);
        if (tabIcon != 0) {
            imageView.setBackgroundResource(tabIcon);
        } else {
            ViewUtils.setGone(imageView, true);
        }
        ((TextView) view.findViewById(R.id.tv_tab)).setText(getTitle(i));

        spec.setIndicator(view);
        host.addTab(spec);

        int background;
        if (i == 0)
            background = getLeftBackground();
        else if (i == count - 1)
            background = getCentreBackground();
        else
            background = getRightBackground();
        view.findViewById(R.id.rl_text).setBackgroundResource(background);
    }
}

From source file:feipai.qiangdan.core.TabPagerActivity.java

/**
 * Create tab using information from current adapter
 * <p>/*from w  ww.j a v a 2  s  .  c o m*/
 * This can be called when the tabs changed but must be called after an
 * initial call to {@link #configureTabPager()}
 */
protected void createTabs() {
    if (host.getTabWidget().getTabCount() > 0) {
        // Crash on Gingerbread if tab isn't set to zero since adding a
        // new tab removes selection state on the old tab which will be
        // null unless the current tab index is the same as the first
        // tab index being added
        host.setCurrentTab(0);
        host.clearAllTabs();
    }

    LayoutInflater inflater = getLayoutInflater();
    int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        TabSpec spec = host.newTabSpec("tab" + i);
        spec.setContent(this);
        View view = inflater.inflate(R.layout.tab, null);
        ImageView imageView = (ImageView) view.findViewById(R.id.iv_icon);
        int tabIcon = getTabIcon(i);
        if (tabIcon != 0) {
            imageView.setBackgroundResource(tabIcon);
        } else {
            ViewUtils.setGone(imageView, true);
        }
        ((TextView) view.findViewById(R.id.tv_tab)).setText(getTitle(i));

        spec.setIndicator(view);
        host.addTab(spec);

        int background;
        if (i == 0)
            background = getLeftBackground();
        else if (i == count - 1)
            background = getCentreBackground();
        else
            background = getRightBackground();
        view.findViewById(R.id.view_line).setBackgroundResource(background);
    }
}

From source file:com.zion.adapter.CachedImageCursorAdapter.java

public void loadBitmap(int resId, ImageView imageView) {
    if (CachedImageCursorAdapter.cancelPotentialWork(resId, imageView)) {
        final CachedImageCursorAdapter.BitmapWorkerTask task = new CachedImageCursorAdapter.BitmapWorkerTask(
                imageView);/*from w w w . ja  v  a  2  s .c  om*/
        imageView.setBackgroundResource(R.drawable.no_image);
        task.execute(resId);
    }
}

From source file:org.odk.collect.android.widgets.SelectMultiWidgetGridLayout.java

@SuppressWarnings("unchecked")
public SelectMultiWidgetGridLayout(Context context, FormEntryPrompt prompt) {
    super(context, prompt);
    mPrompt = prompt;/*from  w w w .  j a  va2  s .  c  o m*/
    mCheckboxes = new ArrayList<CheckBox>();

    // SurveyCTO-added support for dynamic select content (from .csv files)
    XPathFuncExpr xPathFuncExpr = ExternalDataUtil.getSearchXPathExpression(prompt.getAppearanceHint());
    if (xPathFuncExpr != null) {
        mItems = ExternalDataUtil.populateExternalChoices(prompt, xPathFuncExpr);
    } else {
        mItems = prompt.getSelectChoices();
    }

    setOrientation(LinearLayout.VERTICAL);

    Vector<Selection> ve = new Vector<Selection>();
    if (prompt.getAnswerValue() != null) {
        ve = (Vector<Selection>) prompt.getAnswerValue().getValue();
    }
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int screenWidth = size.x;
    int height = size.y;

    int halfScreenWidth = (int) (screenWidth * 0.5);
    int quarterScreenWidth = (int) (halfScreenWidth * 0.5);

    glayout = new GridLayout(getContext());
    glayout.setOrientation(0);
    glayout.setColumnCount(2);
    //glayout.setRowCount(2);

    int row_index = 0;
    int col_index = 0;

    if (mItems != null) {
        for (int i = 0; i < mItems.size(); i++) {
            // no checkbox group so id by answer + offset
            CheckBox c = new CheckBox(getContext());
            c.setTag(Integer.valueOf(i));
            c.setId(QuestionWidget.newUniqueId());
            c.setText(prompt.getSelectChoiceText(mItems.get(i)));
            c.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
            c.setFocusable(!prompt.isReadOnly());
            c.setEnabled(!prompt.isReadOnly());

            for (int vi = 0; vi < ve.size(); vi++) {
                // match based on value, not key
                if (mItems.get(i).getValue().equals(ve.elementAt(vi).getValue())) {
                    c.setChecked(true);
                    break;
                }

            }
            mCheckboxes.add(c);
            // when clicked, check for readonly before toggling
            c.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (!mCheckboxInit && mPrompt.isReadOnly()) {
                        if (buttonView.isChecked()) {
                            buttonView.setChecked(false);
                            Collect.getInstance().getActivityLogger().logInstanceAction(this,
                                    "onItemClick.deselect",
                                    mItems.get((Integer) buttonView.getTag()).getValue(), mPrompt.getIndex());
                        } else {
                            buttonView.setChecked(true);
                            Collect.getInstance().getActivityLogger().logInstanceAction(this,
                                    "onItemClick.select", mItems.get((Integer) buttonView.getTag()).getValue(),
                                    mPrompt.getIndex());
                        }
                    }
                }
            });

            String audioURI = null;
            audioURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_AUDIO);

            String imageURI;
            if (mItems.get(i) instanceof ExternalSelectChoice) {
                imageURI = ((ExternalSelectChoice) mItems.get(i)).getImage();
            } else {
                imageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i),
                        FormEntryCaption.TEXT_FORM_IMAGE);
            }

            String videoURI = null;
            videoURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "video");

            String bigImageURI = null;
            bigImageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "big-image");

            MediaLayout mediaLayout = new MediaLayout(getContext());
            mediaLayout.setAVT(prompt.getIndex(), "." + Integer.toString(i), c, audioURI, imageURI, videoURI,
                    bigImageURI);
            // mediaLayout.setAVT(index, selectionDesignator, text, audioURI, imageURI, videoURI, bigImageURI);
            // addView(mediaLayout);

            row_index = i / 2 + 1;
            col_index = i % 2;

            int orientation = display.getOrientation();
            if (orientation == 1) {
                halfScreenWidth = height / 2;
            } else {
                halfScreenWidth = screenWidth / 2;
            }

            Spec row = GridLayout.spec(row_index);
            Spec col = GridLayout.spec(col_index);
            GridLayout.LayoutParams first = new GridLayout.LayoutParams(row, col);
            first.width = halfScreenWidth;
            // first.height = quarterScreenWidth * 2;
            glayout.addView(mediaLayout, first);

            // Last, add the dividing line between elements (except for the last element)
            ImageView divider = new ImageView(getContext());
            divider.setBackgroundResource(android.R.drawable.divider_horizontal_bright);
            if (i != mItems.size() - 1) {
                if (col_index == 0)
                    glayout.addView(divider);
            }

        }
    }
    addView(glayout);
    mCheckboxInit = false;

}

From source file:com.pixate.freestyle.fragment.GridViewFragment.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub

    /** ImageView for each grid view item */
    ImageView imageView;
    if (convertView == null) {
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(mWidth, mHeight));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    } else {/*  ww  w. ja  v  a2s .c  om*/
        imageView = (ImageView) convertView;
    }

    imageView.setBackgroundResource(R.drawable.grid_item_background);

    return imageView;
}

From source file:com.chrslee.csgopedia.app.CardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    //Looks like he did this layout via code this is a layoutparams object
    //it defines the metrics and bounds of a specific view
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    //Creating a FrameLayout a FrameLayout is basically a empty container
    FrameLayout fl = new FrameLayout(context);
    fl.setLayoutParams(params);//w  w  w .j  a v  a  2s .  c  o m
    //setting the params from above

    // First - image section
    //Building the imageview via code
    LayoutParams imgParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    imgParams.gravity = Gravity.CENTER;
    //setting all centered
    ImageView iv = new ImageView(context);
    iv.setLayoutParams(imgParams);
    iv.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    iv.setAdjustViewBounds(true);
    iv.setBackgroundResource(getActivity().getIntent().getExtras().getInt("iconID"));
    //seting the iconID as the image of this imageView

    // Second - prices section
    //final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources()
    //        .getDisplayMetrics());
    //

    //LinearLayout is another container it just take the
    //widgets inside it and display them in a linear order
    LinearLayout linLayout = new LinearLayout(context);
    linLayout.setOrientation(LinearLayout.VERTICAL);
    linLayout.setLayoutParams(params);
    linLayout.setGravity(Gravity.CENTER);

    // Get prices
    ConnectionDetector cd = new ConnectionDetector(context); //creating a connection detector to check for internet
    String query = getActivity().getIntent().getStringExtra("searchQuery"); //taking the name or whatever he pass from mainactivity from the searchquery arg
    TextView placeholder = new TextView(context); ///this is a textview for the name of the item
    if (cd.isConnectedToInternet()) {//if its connected to internet then
        if (query.equals("-1")) {//if the skin is regular he display is not for sale
            placeholder.setText("Regular skins are not for sale!");
            linLayout.addView(placeholder);
        } else {//else he calls the scrappperAsyncTask with the query
            new ScraperAsyncTask(linLayout).execute(query);
        }
    } else {//if its not connected he display the message here
        placeholder.setText("Please connect to the Internet to view prices.");
        linLayout.addView(placeholder);
    }

    //here he defines which tab he is displaying, Now I see why he used the same fragment,
    //this is a bad practice, he created both widgets before but just displays one of them
    //for each case if its the first tab he display the image if its the second the prices
    if (position == 0) {
        fl.addView(iv);
    } else {
        fl.addView(linLayout);
    }

    //Then he returns the framelayout (container) to display it in the screen
    return fl;
}

From source file:com.shollmann.igcparser.ui.activity.IGCFilesActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.files_menu, menu);
    MenuItem menuSearchEntireSdCard = menu.findItem(R.id.menu_search_sdcard);
    MenuItem menuRefresh = menu.findItem(R.id.menu_refresh);
    MenuItem menuAbout = menu.findItem(R.id.menu_about);
    MenuItem menuShare = menu.findItem(R.id.menu_share);
    MenuItem menuSettings = menu.findItem(R.id.menu_settings);

    ImageView viewAttach = (ImageView) menu.findItem(R.id.menu_sort).getActionView();
    viewAttach.setBackgroundResource(R.drawable.drawable_sort_icon);
    viewAttach.setOnClickListener(new View.OnClickListener() {
        @Override/*w  ww  . j a va2s . co  m*/
        public void onClick(View v) {
            showSortDialog(v);
        }

    });

    menuSearchEntireSdCard.setOnMenuItemClickListener(this);
    menuRefresh.setOnMenuItemClickListener(this);
    menuAbout.setOnMenuItemClickListener(this);
    menuShare.setOnMenuItemClickListener(this);
    menuSettings.setOnMenuItemClickListener(this);
    return super.onCreateOptionsMenu(menu);
}