Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7407467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:43:37+00:00 2026-05-29T05:43:37+00:00

Evening, I came across this very useful post and I have everything looking good

  • 0

Evening,

I came across this very useful post and I have everything looking good except for sizing…
Post: how to add icon in alert dialog before each item?

There was a comment about setBounds and then invoking a different setCompoundDrawables.

Here is what I have

...
switch(currently_selected){
...
    case 3:

                final Item[] items2 = {
                    new Item("Company 1", R.drawable.c_1),
                    new Item("Company 2", R.drawable.c_2),
                    new Item("Company 3", R.drawable.c_3),
                    new Item("Company 4", R.drawable.c_4),
                    new Item("Company 5", R.drawable.c_5)//no icon for this one
                };

                ListAdapter adapter = new ArrayAdapter<Item>(
                                                MainPortal.this,
                                                android.R.layout.select_dialog_item,
                                                android.R.id.text1,
                                                items2){
                        public View getView(int position, View convertView, ViewGroup parent) {
                            //User super class to create the View
                            View v = super.getView(position, convertView, parent);
                            TextView tv = (TextView)v.findViewById(android.R.id.text1);

                            //Put the image on the TextView

                            tv.setCompoundDrawablesWithIntrinsicBounds(items2[position].icon, 0, 0, 0);

                            //Add margin between image and text (support various screen densities)
                            int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
                            tv.setCompoundDrawablePadding(dp5);

                            return v;
                        }
                    };

                AlertDialog.Builder builder1 = new AlertDialog.Builder(MainPortal.this);
                builder1.setTitle("Please select the Module you wish to load and use");
                builder1.setAdapter(adapter, new DialogInterface.OnClickListener() {
                //builder1.setItems(items1, new DialogInterface.OnClickListener() { // comment out this line to try to use the adapter
                    public void onClick(DialogInterface dialog, int item) {
                        Toast.makeText(getApplicationContext(), items1[item], Toast.LENGTH_LONG).show();
                    }
                }).create().show();

                break;
...
}//end switch

so this works very well and after 5-6 hours I got it working.

Though I’m too new at this to understand what some of these things are.
My company 1-5, will have the option to load a company header to kind of display alongside the name.

I’d like to scale these down while maintaining their aspect ratios if possible.
thus,

int max_allowed = 50;
if(getWidth() > getHeight){
    scaleTo(50, (getWidth()/getHeight()*50));
}else if(getWidth() < getHeight){
    scaleTo((getWidth()/getHeight()*50), 50) ;
}else{
    scaleTo(50, 50);
}

Any and help towards the proper way to set the bounds would be greatly appreciated, I just don’t understand the items2[position].icon being an integer and referencing or converting a drawable from it.

thanks,
Joshua

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:43:38+00:00Added an answer on May 29, 2026 at 5:43 am

    I managed to find the answer after a fair bit of digging.

    The changes required were as follows in order to resize. After which a simple if statement will suffice to adjust company banner sizes

    final Drawable image;
    Resources res = getResources();
    image = res.getDrawable(items2[position].icon);
    image.setBounds(0, 0, 50, 50);
    tv.setCompoundDrawables(image, null, null, null);
    
    //tv.setCompoundDrawablesWithIntrinsicBounds(image,0,0,0);//items2[position].icon, 0, 0, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across a section on MSDN this evening talking about #pragma options. Specifically,
Good evening. For a project, I have to create a system. In this system,
Good evening StackOverflow This time I'm fighting with a ListView Containing TextViews. I add
Good evening :-)! I have this code to use Drag & Drop method for
Good evening, I'm having an issue with Masonry. This is all my relevant code:
Good evening, I would like to have a navigation bar which is centralised to
Good evening, In my app that I'm currently developing, I have a class that
Good evening, i need to know how can i have one .h file that
Good evening fellow coders, and thank you in advance for any help/attention. This is
Good evening I have a JTable that I built with a TableModel how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.