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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:03:27+00:00 2026-06-13T20:03:27+00:00

Trying to get the data behind a specific position item from my created and

  • 0

Trying to get the data behind a specific position item from my created and populated gridView.
Below listener method setOnItemClickListener() works well,but what i need is to get info on rendering the screen(gridview) not only on item click.

This is a snipped from my activity:

    ImageAdapter adapter = new ImageAdapter(LaunchActivity.this,
                myArray, elements);
        gridview.setAdapter(adapter);

        gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v,
                    int position, long id) {

                ImageView iv = (ImageView) v.findViewById(R.id.icon_image);
                iv.setImageDrawable(getResources()
                        .getDrawable(R.drawable.drank));
                String name = elements[position].toString();
                System.out.println("===POSITION: " + position);
                if (dbHelper.getElementByPosition(position) == null) {
                    System.out.println("can insert");
                    dbHelper.addElement(new Beer(name, 1, position));
                } else {
                    System.out.println("already exists");
                }
            }
        });

        if (!elements.isEmpty()) {
            for (Element cn : elements) {
            Element item = (Element) gridview.getItemAtPosition(cn.getPosition());



                System.out.println(cn.getPosition() + ", ITEM: " + item);


}
        }

It keeps on returning null…:

[2012-11-04 01:33:46 - Emulator] I/System.out( 1771): 7, ITEM: null
[2012-11-04 01:33:46 - Emulator] I/System.out( 1771): 3, ITEM: null
[2012-11-04 01:33:46 - Emulator] I/System.out( 1771): 11, ITEM: null
[2012-11-04 01:33:47 - Emulator] I/System.out( 1771): 14, ITEM: null
[2012-11-04 01:33:47 - Emulator] I/System.out( 1771): 12, ITEM: null

I don’t understand why i am getting this wrong…
Maybe someone can spot my mistake or just an idea would be great.
Thank you!

  • 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-13T20:03:29+00:00Added an answer on June 13, 2026 at 8:03 pm

    Your grid is not filled up yet by the adapter during onCreate. You have several possibilities. One of them is to use a delayed runnable in onStart for instance

     new Handler().runDelayed( Runnable, long ).
    

    And inside this runnable, your grid will be filled.

    Or better, register a datasetobserver on your adapter and you will know when your grid is filled.

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

Sidebar

Related Questions

So I'm trying to get data from my sql database and sort it by
I am trying to get data back from a PHP file assigned with GET
I am trying to get data from my interface, written in c, to another
I am trying to get the data for the Dow Jones Index from google.
I am trying to get a parameter for my update from the gridview but
I am trying to get data for my collection_select list. Details There are 4
I'm trying to get data by id in my django app. The problem is
I'm trying to get data by id in my django app. The problem is
I am currently trying to get data out of a plist. It basically looks
I am working on an app on Windows Phone and trying to get data

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.