0

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

4

1 回答 1

0

我希望微调器始终在顶部。唯一改变的是微调器下的内容

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

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从回调中调用上述方法:

yourSpinnerRefference.setOnItemSelectedListener(new OnItemSelectedListener() {

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

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

        }
    });

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

编辑:制作两个数组来保存您的数据:

int[] images = {R.drawable.imag1, R.drawable.imag2 ..etc...};
//also for the text
String[] text = {"text1", "text2 ...etc...};

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

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

不需要多个ImageViewand TextViews

于 2013-02-09T16:11:22.943 回答