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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:58:52+00:00 2026-06-03T22:58:52+00:00

I have a question about an ImageAdapter for populating the GridView . Following is

  • 0

I have a question about an ImageAdapter for populating the GridView. Following is the code for my Activity:

public class RestListActivity extends Activity {
    //ImageButton [] buttons;
    RelativeLayout rl;
    int restCount = 0;
    //Resources a;
    int resIndex = 0;
    boolean resFound = false;
    int last;
    int resCount = 0;
    TextView tv;
    ViewFlipper vf;
    private static final int SWIPE_MIN_DISTANCE = 120;
    private static final int SWIPE_MAX_OFF_PATH = 250;
    private static final int SWIPE_THRESHOLD_VELOCITY = 200;
    private GestureDetector gestureDetector;
    View.OnTouchListener gestureListener;
    Vector<Bitmap> iconBmp;
    Vector<GridView> gvs;
    Vector<ImageAdapter> ias;

    // TODO Auto-generated constructor stub
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.restlist);
        rl = (RelativeLayout) findViewById(R.id.layoutRestPage);

        //a=this.getResources();
        boolean done = true;

        tv = (TextView) findViewById(R.id.textView1);
        tv.setText("Sistemi kullandığınız için teşekkür ederiz!");

        Button nb = (Button) findViewById(R.id.nextButton);
        nb.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                vf.setInAnimation(RestListActivity.this, R.anim.view_right_transition_in);
                vf.setOutAnimation(RestListActivity.this, R.anim.view_right_transition_out);
                vf.showNext();
            }
        });
        Button pb = (Button) findViewById(R.id.prevButton);
        pb.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                vf.setInAnimation(RestListActivity.this, R.anim.view_left_transition_in);
                vf.setOutAnimation(RestListActivity.this, R.anim.view_left_transition_out);
                vf.showPrevious();
            }
        });
        Button backButton = (Button) findViewById(R.id.restButton);
        backButton.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                Log.i("ACTION", "AD BUTTON CLICKED");
                try {
                    Intent i = new Intent(RestListActivity.this, AVMOrderSystemMain.class);
                    startActivity(i);
                } catch (Exception e) {
                    Log.i("cort", e.toString());
                }
            }
        });
        Button hb = (Button) findViewById(R.id.helpButton);
        hb.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(RestListActivity.this,
                        "\tSiparis vermek için bir restoran reklamına tıklayarak\n" +
                                "ilgili restoranın sayfasına gidebilir, ya da restoranlar\n" +
                                "listesinden bir restoran seçerek, yine ilgili restoranın\n" +
                                "sayfasına gidebilirsiniz.\n" +
                                "\tBu sayfadan menü tercihinizi yaparak detayları belirledikten\n" +
                                "sonra siparişinizi onaylayarak ödemeniz gereken tutarı\n" +
                                "öğrenebilirsiniz\n", Toast.LENGTH_LONG).show();
            }
        });

        gestureDetector = new GestureDetector(new MyGestureDetector());
        gestureListener = new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                if (gestureDetector.onTouchEvent(event)) {
                    return true;
                }
                return false;
            }
        };
        //************************************************************************************
        //************************************************************************************
        //************************************************************************************
        ias = new Vector<ImageAdapter>();
        iconBmp = new Vector<Bitmap>();
        gvs = new Vector<GridView>();
        for (int i = 0; i < StaticParameters.getCompleteData().getRestaurantsVector().size(); i++) {
            System.out.println("_______________________________________-_-_-_-" +
                    StaticParameters.getCompleteData().getRestaurantsVector().get(i).getActiveImage());
            byte[] imgBytes = FileHandler.readFile2(this, "main_icons", StaticParameters.getCompleteData().getRestaurantsVector().get(i).getActiveImage());
            iconBmp.add(BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length));
            System.out.println("///////////////77"+imgBytes.length);
        }
        System.out.println("))))))))))))))" + iconBmp.size());
        //************************************************************************************
        vf = (ViewFlipper) findViewById(R.id.restFlipper);

        int count = iconBmp.size();
        Log.i("THE SIZE", "=" + count);

        for (int y = 0; y < iconBmp.size(); y+=6) {
            System.out.println("0000000000000000___");
            Vector<Bitmap> bmpSubSet = new Vector<Bitmap>();
            for (int o = 0; o < 6 && o + y < iconBmp.size(); o++) {
                System.out.println("INSIDE!!!!");
                bmpSubSet.add(iconBmp.get(o + y));
            }
            ImageAdapter ia = new ImageAdapter(this);
            ia.setBitmaps(bmpSubSet);
            ias.add(ia);
            GridView gv = new GridView(this);

            gv.setId(y);
            gv.setLayoutParams(new GridView.LayoutParams(800, 600));
            gv.setBackgroundColor(Color.WHITE);
            gv.setNumColumns(3);
            gv.setColumnWidth(GridView.AUTO_FIT);
            gv.setVerticalSpacing(5);
            gv.setHorizontalSpacing(5);
            gv.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);

            System.out.println("++++++++++++++++4"+ia.restLogos.size());
            gv.setAdapter(ia);
            gv.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                    try {
                        /*Intent i = new Intent(RestListActivity.this,RestPageActivity.class);
                     RestPageActivity.setText(h);
                     startActivity(i);*/
                    } catch (Exception e) {
                        Log.i("cort", e.toString());
                    }
                }
            });
            vf.addView(gv);
        }

        //////////////////////////////////////////////////////

    }

    class MyGestureDetector extends SimpleOnGestureListener {
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            try {
                if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
                    return false;
                // right to left swipe
                if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                    vf.setInAnimation(RestListActivity.this, R.anim.view_left_transition_in);
                    vf.setOutAnimation(RestListActivity.this, R.anim.view_left_transition_out);
                    vf.showPrevious();
                } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                    vf.setInAnimation(RestListActivity.this, R.anim.view_right_transition_in);
                    vf.setOutAnimation(RestListActivity.this, R.anim.view_right_transition_out);
                    vf.showNext();
                }
            } catch (Exception e) {
                // nothing
            }
            return false;
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (gestureDetector.onTouchEvent(event))
            return true;
        else
            return false;
    }
}

And the following is the ImageAdapter:

public class ImageAdapter extends BaseAdapter {
    private Context mContext;
    private ArrayList <Integer> restLogoIDs=new ArrayList<Integer>();
    private Resources res;
    Vector <Bitmap>  restLogos=new Vector<Bitmap>();
    public ImageAdapter(Context c) {
        mContext = c;
    }
    public void setResources(Resources r)
    {
        res=r;
    }
    public void setImageIDs(ArrayList <Integer> restLogoIDs)
    {
        this.restLogoIDs=restLogoIDs;
    }
    ////////////////////////////////////////////////////////
    public void setBitmaps(Vector <Bitmap> restLogos)
    {
        this.restLogos=restLogos;
        System.out.println("$$$$$$$$$$$$$$$$$$$$"+restLogos.size());
    }
    ////////////////////////////////////////////////////////
    public int getCount() {
        return restLogoIDs.size();
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        System.out.println("=============xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx---"+position);
        ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(180, 180));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            //imageView.setPadding(8, 8, 8, 8);
        } else {
            imageView = (ImageView) convertView;
        }

        //BURASI DEĞİŞECEK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        //imageView.setImageResource(restLogoIDs.get(position));
        imageView.setImageBitmap(restLogos.get(position));
        return imageView;
    }
    // references to our images
}

When I print the number of Bitmaps and the size in the adapter after I set them in the main Activity, I see that the number of Bitmaps is correct. For some reason, getView() from the adapter is not being called. I can see the GridView but it’s empty. Can I get some help with this?

  • 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-03T22:58:54+00:00Added an answer on June 3, 2026 at 10:58 pm

    The method getCount of your adapter returns 0 meaning, for the adapter, that it has no elements and it doesn’t call the getView method:

    public int getCount() {
            return restLogoIDs.size(); // you only instantiate restLogoIds, you never add some values to it
    }
    

    Instead of restLogoIds which you never assign any values(its size is 0) use restLogos which you actually assign some values so it isn’t empty or add some values to restLogoIds when you set the adapter.

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

Sidebar

Related Questions

I have question about throw. How will the throw work in the following code?
I have question about removing element from QList. myclass.h: class node2D : public QObject
I have a question about the objective-C. I use the following code to add
I have question about my code which does the Hoare Partition Method. Here is
I have a question about the compliance mode. What happens with my class which
I have a question about best practices with the Module Design Pattern. The code
I have a question about how the System class works. Lets say there is
I'm learning asp.net. I have question about example buttons I can use two types
I have question about try, catch and finally in Java. Consider the following scenario:
https://stackoverflow.com/a/64983/468251 - Hello, I have question about this code, how made that working with

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.