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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:37:18+00:00 2026-05-25T23:37:18+00:00

What I tried Hello Guys, I have made a GridView which I’ve filled over

  • 0

What I tried


Hello Guys, I have made a GridView which I’ve filled over my database. Now I made an onItemClickListner, from the Google GridView tutorial. Now I tried to make that when the user clicks on a picture in the GridView, it keeps selected and gets a backgroundcolor so the user sees which Image he chooses.
But exactly this isn’t working how it should. I made a If with a boolean which allways when the User clicks on the next View, that the old View gets transperent again and the new clicked View got a backgroundcolor. But after I selected a View and I scroll up and down. The highlighted View changes sometimes randomstyled.

Question


So my question is what I have to change in my onItemClickListner, that this random View changing stops (?), I didn’t found out a way to do so. And is there a easier way to highlight the selected View?
For the understanding “selected View” = User clicks on it, than its selected and should be highlighted.

Code


Here’s the Code of my onItemClickListner:

    //Hier wird die Grindview gefüllt
    final GridView gridview = (GridView) findViewById(R.id.SmileyGrind);
    gridview.setAdapter(new ImageAdapter(this, info));


    //Hier wird gemerkt welches bild
    gridview.setOnItemClickListener(new OnItemClickListener() {

boolean color = false;
View vv;


        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            Toast.makeText(SFilterConfigActivity.this, "" + position, Toast.LENGTH_SHORT).show();
           // gridview.setSelection(position);

            if ( color == false){
                v.setBackgroundColor(0xFF00FF00);
                vv = v;
                color = true;

            }
            else {
                vv.setBackgroundColor(0x00000000);
                v.setBackgroundColor(0xFF00FF00);
                vv = v;


            }


        }      
    });

Thx for you help in Advance!

  • 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-25T23:37:18+00:00Added an answer on May 25, 2026 at 11:37 pm

    I had the same issue but it was with ListView .follow this it will work for GridView too.

    if(position == grid.getSelectedItemPosition())
       holder._linear.setBackgroundColor(Color.GRAY);           
    else  
       holder._linear.setBackgroundColor(Color.BLACK);
    

    and get the Parent Layout of the Layout that you are using for your GridView and on onClick method of layout just add this .

     holder._linear.setBackgroundColor(Color.GRAY); 
    

    This will change the Background color of the layout and the above code will solve your random background problem.

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

Sidebar

Related Questions

What I've tried Hello Guys, I first created a database which I've filled with
Hello guys I am working on silverlight and I have issue regarding on database
I have tried to send mail from command line: echo hello world | mail
Hello guys i have installed wamp server Version 2.0 .. and i have tried
I have tried to generate Hello World with openxml sdk. To my surprise when
Hello I have one c++ Programming assignment question. I tried hard but somehow I
Hello guys i have cells in tableview, but there are two different UIButtons to
Hello guys I have a DIV that I got passed trought a js function
I tried hello world example from here and I can't see any output in
I tried echo print 'hello' | ipython Which runs the command but ipython immediately

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.