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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:27:35+00:00 2026-05-31T01:27:35+00:00

am getting an error in my GridView, am displaying a grid view from strings.

  • 0

am getting an error in my GridView, am displaying a grid view from strings. I want to show an alert dialog when i select any row of the grid view. But My problem is when am scrolling the grid view it is showing the Alert Dialog. Here is my code.

grid = (GridView) findViewById(R.id.grid);
    grid.setAdapter(/*Adapter class*/);

    grid.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View v,   int pos, long id) {
            final AlertDialog alertDialog = new AlertDialog.Builder(ApprovePunches.this).create();
            alertDialog.setTitle("Approve...");
            alertDialog.setMessage("Are you sure?");
            alertDialog.setButton("ok", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int which) {
                 alertDialog.dismiss();
               }
            });
            alertDialog.setButton2("Cancel", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int which) {
                     alertDialog.dismiss();
                   }
                });

            alertDialog.setIcon(android.R.drawable.alert_dark_frame);
            alertDialog.show();

        }



        @Override
        public void onNothingSelected(AdapterView<?> arg0) {


        }
    });

Can anyone please help me in doing this. 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-05-31T01:27:36+00:00Added an answer on May 31, 2026 at 1:27 am

    This is because you are trying to show a Alert Dialog in onItemSelected Listener. Your onItemSelectedListener gets called when ever there is a change in your View.(Eg. During Scroll event ).

    If you want to display a Dialog based on user action, you can use setOnItemClickListener like this,

    grid.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View v,   int pos, long id) {
            final AlertDialog alertDialog = new AlertDialog.Builder(ApprovePunches.this).create();
            alertDialog.setTitle("Approve...");
            alertDialog.setMessage("Are you sure?");
            alertDialog.setButton("ok", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int which) {
                 alertDialog.dismiss();
               }
            });
            alertDialog.setButton2("Cancel", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int which) {
                     alertDialog.dismiss();
                   }
                });
    
            alertDialog.setIcon(android.R.drawable.alert_dark_frame);
            alertDialog.show();
    
        }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I am deleting a row from grid view I am getting following error.
I'm trying to extract the ID from a gridview row but I keep getting
Getting this error when updating a row via a gridview with a sqldatasource in
I am getting an error when attempting to call a stored proc from my
I keep getting the above error, going from my first activity that has a
I started getting this error in ASP.NET Gridview SQLDataSource. Everything was fine. In the
<form runat=server id=f1> <div runat=server id=d> grid view: <asp:GridView runat=server ID=g> </asp:GridView> </div> <asp:TextBox
I'm trying to remove a row from my gridview manually, because for some reason,
Using VB.Net If the grid cell value is empty, i am getting error as
I am getting an error here in sorting the gridview. My datasource is a

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.