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

  • Home
  • SEARCH
  • 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 7675569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:59:38+00:00 2026-05-31T16:59:38+00:00

I am doing application and I need to dispaly some images in a gridview.

  • 0

I am doing application and I need to dispaly some images in a gridview. I need to display images in that gridview randomly. So here I taken one integer array like mThumbIds[] in that I add all images, then I take arraylistl like solutionList then that mThumbIds[] intrgerarray.

I added into solutionList array.then i apply random function to that solutionList arrat then agaain i add solutionList array into one integer array like “randomNumbers[]” then finally i add that randomNumbers[] array to gridview i get random images but my probem is in gridview repated images coming,but i dont want repeted images. in mThumbIds[] i am not given repted images.please any one suggest me.

     ImageAdapter .class:
          public class ImageAdapter extends BaseAdapter {
         private Context mContext;

public ImageAdapter(Context c) {

    // TODO Auto-generated constructor stub
    mContext = c;
}

public int getCount() {
    // TODO Auto-generated method stub
    return mThumbIds.length;
}

public Object getItem(int position) {
    // TODO Auto-generated method stub
    return null;
}

public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView;
int unique=0;
    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;
    }
      Collections.shuffle(solutionList);
      Integer[] randomNumbers=(Integer[])solutionList.toArray();
    imageView.setImageResource(randomNumbers[unique]);
    unique++;
    return imageView;
}
private Integer[] mThumbIds={R.drawable.a,R.drawable.bb,R.drawable.cc,R.drawable.dd,R.drawable.ee,R.drawable.ff,R.drawable.galley,R.drawable.gg};
  List<Integer> solutionList = Arrays.asList( mThumbIds);

}
  • 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-31T16:59:39+00:00Added an answer on May 31, 2026 at 4:59 pm

    A solution here is to store indexes of items that are already used in a special ArrayList. And also I’d recommend you using the java.util.Random class instead of shuffling the array everytime. The code will look like this:

    ArrayList<Integer> usedIndexes = new ArrayList<Integer>();
            int index;
            do {
                index = new Random().nextInt(mThumbIds.length);
            } while (usedIndexes.contains(index));
                imageView.setImageResource(randomNumbers[index]);
            usedIndexes.add(index);
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i am doing one application here i need to disply 6 images in
Iam doing one application in iphone.In this i need to get the browsing history
We need to represent huge numbers in our application. We're doing this using integer
I am doing an e-learning application using CakePHP. The problem is that I need
I want to display a progress bar while doing some work, but that would
I'm developing a Web application. I need to display some decimal data correctly so
in my C#-Silverlight-3-Application, I have created a class, that is doing some calculations that
I am working on a Rails 3 application and need to display some test
I need to write a scientific application in C++ doing a lot of computations
I'm doing application for iPhone using C sockets. At some point I'm performing recvfrom

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.