首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当用户被要求从12个选项中选择4个时,如何显示用户选择?

问当用户被要求从12个选项中选择4个时,如何显示用户选择?
EN

Stack Overflow用户
提问于 2017-04-05 06:00:55
回答 1查看 33关注 0票数 0

我有一个活动,要求用户构建一顿饭。在这里,他们有12个食物选项可供选择(以图像按钮表示)。我希望用户能够单击这些图像按钮中的四个,并继续下一个活动。但是,我不知道如何在下一个活动中显示4个用户选择的图像按钮。我尝试过使用putExtra()和getExtra()命令,但似乎无法理解。

EN

回答 1

Stack Overflow用户

发布于 2017-04-05 06:10:14

代码语言:javascript
复制
//The Images you want, save as bitmap
imageView.buildDrawingCache();
Bitmap image= imageView.getDrawingCache();

//Create a extras bundle and put bitmap in with key
Bundle extras = new Bundle();
extras.putParcelable("imagebitmap", image);

//Create a new intent and pass in the bundle
Intent intent = new Intent(CurrentActivity.this, NextActivity.class);
intent.putExtras(extras);
startActivity(intent);

//In next activity, grab the extras
Bundle extras = getIntent().getExtras();
//Get the saved bitmap with the key value into a bitmap object
Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");
//Set it
image.setImageBitmap(bmp );

至于这背后的逻辑,我真的帮不上忙,因为我看不到你的代码。但我会在所有的图像视图上建立onClickListeners,并跟踪正在点击的内容

代码语言:javascript
复制
imgView.setOnClickListener(new View.OnClickListener(){
    public void onClick(View v) {

    if (count < 4) {
        imgView.buildDrawingCache();
        Bitmap image= imageView.getDrawingCache();
        extras.putParcelable("imagebitmap" + count, image);
    } else {
        //Tell them to deselect, or add an operation to deselect, and decrement counter
    }
    }
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43218433

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档