English 中文(简体)
如何从电网角度展示图像。 GridView在警示箱内
原标题:how to show a image in a image view, chosen from an gridview.GridView is within in alert box
  • 时间:2011-10-11 17:05:26
  •  标签:
  • android

i 是一种可点击的形象调查(标题是“塑造你的形象”)的活动。 比如:

setContentView(R.layout.main);
        ImageView button = (ImageView)findViewById(R.id.categories);
        button.setClickable(true);

now by clicking the image view a popup/alert opens consisting of a grid view form by images from my drawable folder.Something like this:

protected Dialog onCreateDialog(int id) {   

        switch(id) {   

        case CATEGORY_ID:   

         AlertDialog.Builder builder;   
            Context mContext = this;   
            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);   
            View layout = inflater.inflate(R.layout.categorydialog,(ViewGroup) findViewById(R.id.layout_root));   
            GridView gridview = (GridView)layout.findViewById(R.id.gridview);   
            gridview.setAdapter(new ImageAdapter(this));   

            gridview.setOnItemClickListener(new OnItemClickListener()   
            {
                public void onItemClick(AdapterView<?> parent, View v,int position, long id) {   
                 Toast.makeText(v.getContext(), "Position is "+position, 3000).show();
                 }   
            });

            ImageView close = (ImageView) layout.findViewById(R.id.close);
            close.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v){
              dialog.dismiss();
            }
            });

            builder = new AlertDialog.Builder(mContext);   
            builder.setView(layout);   
            dialog = builder.create();   
            break;   
        default:   
            dialog = null;   
        }   
        return dialog;   
    }

i 能够点击这些图像。

Problem:
i want to choose one from these images and set it in the image view which user had clicked. any suggestios! Thanks!!

最佳回答

更改<代码> 实地观察

public class YourActivityName extends Activity
{
    private ImageView mImageView;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mImageView = (ImageView)findViewById(R.id.categories);
        mImageView.setClickable(true);
    }

}

Then in your gridview s onItemClick you can call mImageView.setImageBitmap (or setImageDrawable.. whichever of the setImage..() methods you need).

gridview.setOnItemClickListener(new OnItemClickListener()   
{
    public void onItemClick(AdapterView<?> parent, View v,int position, long id) {   
          Bitmap bmp = ...; //get your image at this position somehow
          mImageView.setImageBitmap(bmp);
    }   
});

你需要获得你点击的图像,但我会把这种图像留给你,因为我不知道你的<密码>。

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签