我正在编写一个android活动的代码,它将在网格视图中显示存储在手机上的图像的缩略图。选择图片后,会弹出自定义对话框。此对话框在图像视图中显示更大版本的图像,以及用于将用户引导回图片集显示的“取消”按钮以及将启动下一个活动的“选择”按钮。当我在Cancel.setOnClickListener方法中放置一个覆盖时,编译器说它是一个错误,并建议我删除它。当我删除它时,编译器再次抱怨并说需要覆盖。有人可以帮帮我吗?任何帮助,将不胜感激。
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();
}
}
}
答案 0 :(得分:1)
@Override
始于Java 6,因此请确保使用正确的源目标和JDK进行编译。
如果您在没有@Override
的情况下收到错误,则听起来您的拼写错误。 @Override
始终是可选的。