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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:40:53+00:00 2026-05-21T03:40:53+00:00

I am writing the code of an android activity that will display thumbnails of

  • 0

I am writing the code of an android activity that will display thumbnails of images stored on the phone in a grid view. When a picture is selected, a custom dialog pops up. This dialog box displays a bigger version of the image in an image view, as well as a Cancel Button that directs the user back to the picture collection display and a Select Button that will start a next activity. When I put an override in the Cancel.setOnClickListener Method, the compiler says it’s an error and recommends that I remove it. When I remove it, the compiler complains again and says that an override is needed. Can any body help me please? Any help would be appreciated.

package com.picturechoiceactivity;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.Toast;
import android.provider.MediaStore;
import android.provider.MediaStore.Images.Thumbnails;
import android.net.Uri;
import android.widget.AdapterView.OnItemClickListener;



public class MainActivity extends Activity {
    public Cursor myImageCursor;
    public int columnNumber;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        String[] imageIDs = new String[]{MediaStore.Images.Thumbnails.IMAGE_ID};

        Uri myImagesSource = MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI;


        String[] projection = {
                MediaStore.Images.ImageColumns._ID,  // The columns we want
                MediaStore.Images.Thumbnails.IMAGE_ID,  
                MediaStore.Images.Thumbnails.KIND };
        String selection = MediaStore.Images.Thumbnails.KIND + "="  + // Select only mini's
        MediaStore.Images.Thumbnails.MINI_KIND;

        myImageCursor = this.managedQuery(myImagesSource, projection, selection, null, null);


        if (myImageCursor == null)
        {
            columnNumber = myImageCursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);

            GridView PhoneImageView = (GridView)findViewById(R.id.imageview);
            PhoneImageView.setAdapter(new ImageAdapter(this));

            PhoneImageView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View v,
                        int position, long id) {
                    String[] data = { MediaStore.Images.Media.DATA };

                    final Cursor  viewImageCursor = managedQuery(
                            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, data,
                            null, null, MediaStore.Images.Thumbnails._ID );
                    final int imageColumnIndex = viewImageCursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                    viewImageCursor.moveToPosition(position);
                    viewImageCursor.moveToFirst();
                    final String filepath = viewImageCursor.getString(imageColumnIndex);
                    Toast.makeText(MainActivity.this, filepath, Toast.LENGTH_LONG).show();

                    Bitmap yourSelectedImage = BitmapFactory.decodeFile(filepath);
                       final Dialog dialog = new Dialog(MainActivity.this);
                       dialog.setContentView(R.layout.dialog);
                       dialog.setTitle("Picture in full-view");
                       dialog.setCancelable(true);


                       ImageView image = (ImageView) dialog.findViewById(R.id.imagev);

                       image.setImageBitmap(yourSelectedImage);


                       Button cancel = (Button) dialog.findViewById(R.id.selectimage);

                       cancel.setOnClickListener(new OnClickListener() {
                          @Override
                           public void onClick(View v) /*error shown here*/ {

                              dialog.dismiss();
                           }
                       });

                       Button select = (Button) dialog.findViewById(R.id.cancelselection);
                       select.setOnClickListener(new OnClickListener() {
                           public void onClick(View v) {
                            //String i = viewImageCursor.getString(imageColumnIndex);
                            //System.gc();
                            Intent intent = new Intent(getApplicationContext(), CategoryActivity.class);
                            intent.putExtra("filename", filepath);
                            startActivity(intent);

                           }
                       }); 
                       dialog.show();

                    }
                }
            );
        }
        else
        {
            Toast.makeText(MainActivity.this, "Gallery is empty.", Toast.LENGTH_LONG).show();
        }

    }       
}
  • 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-21T03:40:53+00:00Added an answer on May 21, 2026 at 3:40 am

    @Override for interfaces began in Java 6, so make sure you are compiling with the right source target and JDK.

    If you are getting an error without @Override then it sounds like you have a spelling error. @Override is always optional.

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

Sidebar

Related Questions

i'm currently writing on some piece of code in android 2.1 that is supposed
I'm writing an Android app for work that shows the status of our phone
I'm writing code that looks similar to this: public IEnumerable<T> Unfold<T>(this T seed) {
I find myself writing code that looks like this a lot: set<int> affected_items; while
I'm writing an application for Android that uses symmetric key encryption to protect sensitive
When writing code do you consciously program defensively to ensure high program quality and
After writing code to populate textboxes from an object, such as: txtFirstName.Text = customer.FirstName;
When I am writing code in Python, I often need to remove items from
I frequently find myself writing code like this: List<int> list = new List<int> {
I'm writing code like this, doing a little quick and dirty timing: var sw

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.