从Spinner
中选择项目后,如何显示不同的内容?我想创建一个Spinner
与连锁店的位置。
发布于 2013-02-10 00:11:23
我想让旋转器总是在上面。,
,the,the,top。唯一变化的是微调器下的内容
在您的活动中创建一个简单的方法来刷新Spinner
下面的布局(它将保持不变)。该方法将从Spinner
上设置的OnItemSelectedListener
调用。它应该是这样的:
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.
}
不需要多个ImageView
和TextViews
。
https://stackoverflow.com/questions/14789552
复制相似问题