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 8423791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:49:18+00:00 2026-06-10T03:49:18+00:00

I am new to android and I am trying to do 1 small project

  • 0

I am new to android and I am trying to do 1 small project in it..
I am trying to get a picture from the drawable folder and cutting it into 9 pieces and storing those pieces in a bitmap array..I was able to do that..

Now, how do i retrieve those pieces from the bitmap array and display it on the imageview?

I have used a gridview in the UI to show the images…. but am not able to assign the bitmap array to the imageResource…

ok, here is what i am trying to do..

public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView;
    Activity activity=(Activity)mContext;
    Resources res=activity.getResources();
    if (convertView == null) {  // if it's not recycled, initialize some attributes
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
        //imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(8, 8, 8, 8);
    } else {
        imageView = (ImageView) convertView;
    }

    Bitmap img=BitmapFactory.decodeResource(res, R.drawable.kite);
    createBitmapPieces(img);
    imageView.setImageResource(bmp[2]);//I dont know how to set the image from the array
}

public Bitmap[] createBitmapPieces(Bitmap source){

    int k=0;
    int width=source.getWidth();
    int height=source.getHeight();
    for(int i=0;i<3;i++){
       for(int j=0;j<3;j++){
        bmp[k]=Bitmap.createBitmap(source,(width*j)/3,(i*height)/3,width/3,height/3);
        k++;
    }

    }
    return bmp;
    } 
  • 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-06-10T03:49:19+00:00Added an answer on June 10, 2026 at 3:49 am

    You can assign only one Bitmap to an ImageView. If you want to use an array, you have to extend the ImageView class, and handle the array yourself in your custom View.

    Two things you have to do:

    1.) You have to create a public method for setting the Bitmap array to a new private field.

    2.) You have to overwrite the onDraw(Canvas canvas) method and draw the Bitmaps in the array instead of drawing a single Drawable.

    EDIT: I might have misunderstood your question, if you try to add the Bitmaps to the GridView, instead of a single ImageView, then you can do it with a custom adapter:

    public class ImageAdapter extends BaseAdapter {
        private Context mContext;
        private Bitmap[] mPics;
    
        public ImageAdapter(Context c, Bitmap[] pics) {
            mContext = c;
            mPics = pics
        }
    
        public int getCount() {
            return mPics.length;
        }
    
        public Object getItem(int position) {
            return mPics[position];
        }
    
        public long getItemId(int position) {return 0;}
    
        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView;
            if (convertView == null) {  // if it's not recycled, initialize some attributes
                imageView = new ImageView(mContext);
            } else {
                imageView = (ImageView) convertView;
            }
            imageView.setImageDrawable(new BitmapDrawable(getItem(position)));
            return imageView;
        }
    }
    

    And in your Activity:

    GridView grid = (GridView) findViewById(R.id.your_imageview_id);
    grid.setAdapter(new ImageAdapter(this, YOUR_BITMAP_ARRAY));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to Android so I'm writing small programs to get familiar with how things
I am new to Android and trying to practice by making small codes. I
I'm new to android and I'm trying to figure out how to get the
trying to get my first android widget and let me tell you moving from
I am absolutely new to Android Development and am trying to create a small
Hello StackOverflow Users, I am new to android and trying to develop a game
I am new to android..Actually iam trying to increase the RAM Memory of android
I'm trying to record audio this.recorder = new android.media.MediaRecorder(); this.recorder.setAudioSource(android.media.MediaRecorder.AudioSource.MIC); this.recorder.setOutputFormat(android.media.MediaRecorder.OutputFormat.DEFAULT); this.recorder.setAudioEncoder(android.media.MediaRecorder.AudioEncoder.DEFAULT); this.recorder.setOutputFile(pruebaAudioRecorder.mp4); **this.recorder.prepare();**
im new to android and I've been trying to figure out how to display
i am new to android programming and i am trying to develop an app

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.