创建一个显示全景图像的自定义对话框 [英] Creating a custom dialog box that displays a full view image

查看:118
本文介绍了创建一个显示全景图像的自定义对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个显示在全视角的图像,并有选择自定义对话框和取消按钮。被点击以便允许用户在全视图中查看所选图像的图像时,应显示该自定义对话框。图像视图应该是一个从一个GridView选中。选择按钮会显示一个消息,吐司和取消按钮将允许用户退出对话框。我们的想法是,以允许用户看到在全视图中的图像,他或她使他们想在画面的最终选择之前

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.

不过,我有几个问题想做到这一点。我的code如下所示:

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,

};
}

有人可以帮我解决这些问题?任何帮助将大大AP preciated。谢谢

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

推荐答案

我想你需要改变这一行

按钮选择=(按钮)findViewById(R.id.selectimage);

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

按钮选择=(按钮)dialog.findViewById(R.id.selectimage);

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

和同为取消。

选择按钮后,你使用buttonChangePerferences而不是选择...

After select button you used "buttonChangePerferences" instead of "select"...

您,因为您使用R.layout.ImageDialog在布局的名称是大写字母,而应该是有R.layout一个问题只用小写...

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...

您需要添加dialog.show();之后你宣布你的按钮

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

加,因为编译器已经弄糊涂了,你可能需要简单地改写一些线条,在某些时候,当你的应用程序仍然有一个小红色标记在上Exclipse右边的Package Explorer中,你需要去项目菜单,然后CLEAN,并选择您的应用程序,然后单击确定。

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.

这篇关于创建一个显示全景图像的自定义对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆