开发者

Having problems with override

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.T开发者_运维技巧humbnails.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();
        }

    }       
}


@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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜