アラート ダイアログにビットマップ イメージを表示しようとするたびに問題が発生しました。「残念ながら blabla.. が停止しました」と表示され、アプリが強制終了またはクラッシュします。ビットマップ イメージに何か問題があると思います。ありがとう、以下は私のコードです:
enter code here
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setContentView(R.layout.marker_detail);
String valueretrievee=null;
//valueretrieve="2";
//get the large image view
picView = (ImageView) findViewById(R.id.picture);
//get the gallery view
picGallery = (Gallery) findViewById(R.id.gallery);
//create a new adapter
imgAdapt = new PicAdapter(this);
//set the gallery adapter
picGallery.setAdapter(imgAdapt);
//set the click listener for each item in the thumbnail gallery
picGallery.setOnItemClickListener(new OnItemClickListener() {
//handle clicks
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//set the larger image view to display the chosen bitmap calling method of adapter class
picView.setImageBitmap(imgAdapt.getPic(position));
//start
AlertDialog.Builder alertadd = new AlertDialog.Builder(ARTAADAfterTouch.this);
//ImageView imageView = (ImageView) findViewById(R.id.picture);
ImageView imageView = (ImageView) findViewById(R.id.picture);
final Bitmap bitmap = Bitmap.createBitmap(imgAdapt.getPic(position));
imageView.setImageBitmap(bitmap);
alertadd.setView(imageView);
alertadd.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
alertadd.setNegativeButton("No", null);
alertadd.show();
//end
picView.setImageBitmap(bitmap);
}
});
}
public void setData(String valueretrieve)
{
this.valueretrieve=valueretrieve;
}
public String getData()
{
return valueretrieve;
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == RESULT_OK) {
//check if we are returning from picture selection
if (requestCode == PICKER) {
//import the image
}
}
//superclass method
super.onActivityResult(requestCode, resultCode, data);
//the returned picture URI
Uri pickedUri = data.getData();
//declare the bitmap
Bitmap pic = null;
//declare the path string
String imgPath = "";
//retrieve the string using media data
String[] medData = { MediaStore.Images.Media.DATA };
//query the data
Cursor picCursor = managedQuery(pickedUri, medData, null, null, null);
if(picCursor!=null)
{
//get the path string
int index = picCursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
picCursor.moveToFirst();
imgPath = picCursor.getString(index);
}
else
imgPath = pickedUri.getPath();
//pass bitmap to ImageAdapter to add to array
imgAdapt.addPic(pic);
//redraw the gallery thumbnails to reflect the new addition
picGallery.setAdapter(imgAdapt);
//display the newly selected image at larger size
picView.setImageBitmap(pic);
//scale options
picView.setScaleType(ImageView.ScaleType.FIT_CENTER);
}
public class PicAdapter extends BaseAdapter
{
//use the default gallery background image
int defaultItemBackground;
//gallery context
private Context galleryContext;
//array to store bitmaps to display
private Bitmap[] imageBitmaps;
//placeholder bitmap for empty spaces in gallery
Bitmap placeholder;
//Intent ft= getIntent(); // gets the previously created intent
//String firstKeyName = ft.getStringExtra("firstKeyName"); // will return "FirstKeyValue"
public PicAdapter(Context c) {
//instantiate context
galleryContext = c;
//copy right by aaron yong -> OVER HERE
//String firstKeyName = intent.getStringExtra("firstKeyName"); // will return "SecondKeyValue"
//create bitmap array
imageBitmaps = new Bitmap[5];
//decode the placeholder image
//placeholder = BitmapFactory.decodeResource(getResources(), R.drawable.hotel1);
//placeholder = BitmapFactory.decodeResource(getResources(), R.drawable.hotel2);
//more processing
//Intent intent = getIntent();
//String valueretrieve = intent.getStringExtra("firstKeyName");
//set placeholder as all thumbnail images in the gallery initially
for(int i=0; i<imageBitmaps.length; i++)
{
Bundle extras = getIntent().getExtras();
if (extras != null) {
valueretrieve = extras.getString("myFirstKey");
}
TextView theTextView = (TextView) findViewById(R.id.textView2);
theTextView.setText(valueretrieve);
//copy right by aaron yong ->> YESS! msut use equal!!
if(theTextView.getText().equals("1"))
{
imageBitmaps[0] = BitmapFactory.decodeResource(getResources(), R.drawable.shop1);
imageBitmaps[1] = BitmapFactory.decodeResource(getResources(), R.drawable.hotel1);
}
else if(theTextView.getText().equals("2"))
{
imageBitmaps[0] = BitmapFactory.decodeResource(getResources(), R.drawable.it1);
imageBitmaps[1] = BitmapFactory.decodeResource(getResources(), R.drawable.hotel2);
}
else if(theTextView.getText().equals("3"))
{
imageBitmaps[0] = BitmapFactory.decodeResource(getResources(), R.drawable.transport1);
imageBitmaps[1] = BitmapFactory.decodeResource(getResources(), R.drawable.transport2);
}
//imageBitmaps[0] = BitmapFactory.decodeResource(getResources(), R.drawable.hotel1);
//imageBitmaps[1] = BitmapFactory.decodeResource(getResources(), R.drawable.hotel2);
imageBitmaps[i]=placeholder;
}
//get the styling attributes - use default Andorid system resources
TypedArray styleAttrs = galleryContext.obtainStyledAttributes(R.styleable.PicGallery);
//get the background resource
defaultItemBackground = styleAttrs.getResourceId(
R.styleable.PicGallery_android_galleryItemBackground, 0);
//recycle attributes
styleAttrs.recycle();
}
//*************************************************
//return number of data items i.e. bitmap images
public int getCount() {
return imageBitmaps.length;
}
//return item at specified position
public Object getItem(int position) {
return position;
}
//return item ID at specified position
public long getItemId(int position) {
return position;
}
//get view specifies layout and display options for each thumbnail in the gallery
public View getView(int position, View convertView, ViewGroup parent) {
//create the view
ImageView imageView = new ImageView(galleryContext);
//specify the bitmap at this position in the array
imageView.setImageBitmap(imageBitmaps[position]);
//set layout options
imageView.setLayoutParams(new Gallery.LayoutParams(470, 400));
//scale type within view area
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
//set default gallery item background
imageView.setBackgroundResource(defaultItemBackground);
//return the view
return imageView;
}
//helper method to add a bitmap to the gallery when the user chooses one
public void addPic(Bitmap newPic)
{
//set at currently selected index
imageBitmaps[currentPic] = newPic;
}
//return bitmap at specified position for larger display
public Bitmap getPic(int posn)
{
//return bitmap at posn index
return imageBitmaps[posn];
}
}
}
txt 形式の logcat リンク: http://pastebin.com/4DSwxXx8
関連するlogcat
05-10 00:22:24.867: E/AndroidRuntime(2276): FATAL EXCEPTION: main
05-10 00:22:24.867: E/AndroidRuntime(2276): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewGroup.addViewInner(ViewGroup.java:3339)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewGroup.addView(ViewGroup.java:3210)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewGroup.addView(ViewGroup.java:3186)
05-10 00:22:24.867: E/AndroidRuntime(2276): at com.android.internal.app.AlertController.setupView(AlertController.java:413)
05-10 00:22:24.867: E/AndroidRuntime(2276): at com.android.internal.app.AlertController.installContent(AlertController.java:241)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.app.AlertDialog.onCreate(AlertDialog.java:337)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.app.Dialog.dispatchOnCreate(Dialog.java:355)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.app.Dialog.show(Dialog.java:260)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.app.AlertDialog$Builder.show(AlertDialog.java:951)
05-10 00:22:24.867: E/AndroidRuntime(2276): at com.apu.ARTAAD.activity.ARTAADAfterTouch$1.onItemClick(ARTAADAfterTouch.java:123)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.widget.Gallery.onSingleTapUp(Gallery.java:981)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.GestureDetector.onTouchEvent(GestureDetector.java:588)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.widget.Gallery.onTouchEvent(Gallery.java:958)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.View.dispatchTouchEvent(View.java:7246)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1903)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-10 00:22:24.867: E/AndroidRuntime(2276): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2090)
05-10 00:22:24.867: E/AndroidRuntime(2276): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1417)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
05-10 00:22:24.867: E/AndroidRuntime(2276): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2038)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.View.dispatchPointerEvent(View.java:7426)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.os.MessageQueue.nativePollOnce(Native Method)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.os.MessageQueue.next(MessageQueue.java:125)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.os.Looper.loop(Looper.java:124)
05-10 00:22:24.867: E/AndroidRuntime(2276): at android.app.ActivityThread.main(ActivityThread.java:5195)
05-10 00:22:24.867: E/AndroidRuntime(2276): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 00:22:24.867: E/AndroidRuntime(2276): at java.lang.reflect.Method.invoke(Method.java:511)
05-10 00:22:24.867: E/AndroidRuntime(2276): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
05-10 00:22:24.867: E/AndroidRuntime(2276): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
05-10 00:22:24.867: E/AndroidRuntime(2276): at dalvik.system.NativeStart.main(Native Method)
enter code here