首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >同一活动中每个微调器项目的不同内容

同一活动中每个微调器项目的不同内容
EN

Stack Overflow用户
提问于 2013-02-09 23:21:00
回答 1查看 324关注 0票数 0

Spinner中选择项目后,如何显示不同的内容?我想创建一个Spinner与连锁店的位置。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-10 00:11:23

我想让旋转器总是在上面。,

,the,the,top。唯一变化的是微调器下的内容

在您的活动中创建一个简单的方法来刷新Spinner下面的布局(它将保持不变)。该方法将从Spinner上设置的OnItemSelectedListener调用。它应该是这样的:

代码语言:javascript
运行
复制
private void changeAdress(int newSelectedAdress) {
    // The ImageView and the TextView will be already in the layout
    ImageView map = (ImageView) findViewById(R.id.theIdOfTheImage);
    // Set the image. You know the current address selected by the user
    // (the newSelectedAddress int) so get it from the array/list/database
    // where you stored it
    // also set the image
}

onItemSelected回调调用了上面的方法:

代码语言:javascript
运行
复制
yourSpinnerRefference.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view,
                int position, long id) {
                          changeAddress(position);              
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

如果这不是你想要的,请解释。

编辑:创建两个数组来保存数据:

代码语言:javascript
运行
复制
int[] images = {R.drawable.imag1, R.drawable.imag2 ..etc...};
//also for the text
String[] text = {"text1", "text2 ...etc...};

然后在我上面推荐的方法中使用这两个数组:

代码语言:javascript
运行
复制
private void changeAdress(int newSelectedAddress) {
     ((ImageView)findViewById(R.id.mapView1)).setImageResource(images[newSelectedAddress]); 
     // assing an id to the TextView in your layout and do the same as above.
}

不需要多个ImageViewTextViews

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14789552

复制
相关文章

相似问题

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