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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:41:26+00:00 2026-05-20T02:41:26+00:00

I am trying to create a custom dialog box that displays an image in

  • 0

I am trying to create a custom dialog box that displays an image in full-view and has a Select as well as Cancel Button. This custom dialog box should be displayed when an image is clicked so as to allow the user to view the selected image in full-view. The image view should be one that is selected from a GridView. The Select Button will display a Toast message and the Cancel button will allow the user to exit the dialog. The idea is to allow the user to see the image in full-view before he or she makes a final choice on the picture they would like.

However, I am having several problems trying to do this. My code is shown below:

  package com.newapp;


 import android.app.Activity;
 import android.app.Dialog;
 import android.content.DialogInterface;
 import android.content.Context;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.BaseAdapter;
 import android.widget.GridView;
 import android.widget.ImageView;
 import android.widget.Toast;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.ImageView;
 import android.widget.Button;

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
 //error here: R cannot be resolved to a variable

        GridView gridview = (GridView) findViewById(R.id.photogrid);
        gridview.setAdapter(new ImageAdapter(this));

        gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                //Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
                Context mContext = getApplicationContext();
                Dialog dialog = new Dialog(mContext);

                dialog.setContentView(R.layout.ImageDialog);
                dialog.setTitle("Full-image view");

                ImageView image = (ImageView) dialog.findViewById(R.id.image);
                image.setImageResource(R.drawable.android);

                Button select = (Button) findViewById(R.id.selectimage);
                        buttonChangePerferences.setOnClickListener(new OnClickListener() {
                            public void onClick(View v) {

                            Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();


                            }
                        });
                    }

                    Button cancel = (Button) findViewById(R.id.cancelselection);
                        cancel.setOnClickListener(new OnClickListener() 
   //error here: Syntax error on tokens;AnnotationName expected instead
                                        {
                            public void onClick(View v) {
                              dialog.cancel();

                            }
                        });

        })
                    }






       package com.newapp;


       import android.content.Context;
       import android.view.View;
       import android.view.ViewGroup;
       import android.widget.BaseAdapter;
       import android.widget.GridView;
       import android.widget.ImageView;

   public class ImageAdapter extends BaseAdapter{

private Context mContext;

public ImageAdapter(Context c) {
    mContext = c;
}

public int getCount() {
    return mThumbIds.length;
}

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) {
    ImageView imageView;
    if (convertView == null) {  // if it's not recycled, initialize some attributes
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(8, 8, 8, 8);
    } else {
        imageView = (ImageView) convertView;
    }

    imageView.setImageResource(mThumbIds[position]);
    return imageView;
}

// references to our images
private Integer[] mThumbIds = {

        R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7,
        R.drawable.sample_0, R.drawable.sample_1,
        R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7,
        R.drawable.sample_0, R.drawable.sample_1,
        R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7,
        R.drawable.sample_0, R.drawable.sample_1,
        R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7,

};
}

Can somebody help me fix these problems? Any help would much appreciated. Thanks

  • 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-20T02:41:27+00:00Added an answer on May 20, 2026 at 2:41 am

    I think you need to change this line

    Button select = (Button) findViewById(R.id.selectimage);

    into

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

    and the same for cancel.

    After select button you used “buttonChangePerferences” instead of “select”…

    You have a problem with R.layout because you are using R.layout.ImageDialog where the name of the layout is in capital letters while it should be only in lower case…

    you need to add dialog.show(); after you declare your buttons

    plus, because the complier has got confused you may need simply to rewrite some lines and at some point when your application still has a little red mark in the package explorer on the right in Exclipse, you need to go to PROJECT menu then CLEAN and select your application and click OK.

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

Sidebar

Related Questions

I'm trying to create a custom view GhostSurfaceCameraView that extends SurfaceView . Here's my
I'm trying to create a custom JSP tag that would take an array object
I am trying to create a custom accordion for my page to that display
I'm trying to create a custom control - a button - which will have
I've been trying to create a custom control that works exactly like the Panel
I'm stuck! I am trying to create a custom modal dialog. I would like
I am trying to create my first custom Print Dialog in C#. I found
I'm trying to create a custom, in-house application that is going to access other
I'm trying to generate a custom dialog in Android. I create my Dialog like
I'm trying to make a custom dialog to show a view in this dialog.

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.