0
我正在寫一個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();
}
}
}
@馬修 - 謝謝 – 2011-04-05 23:15:52