Android 同一活动中每个微调器项的不同内容
从Android 同一活动中每个微调器项的不同内容,android,android-activity,spinner,Android,Android Activity,Spinner,从微调器中选择项目后,如何显示不同的内容? 我想创建一个带有连锁店位置的微调器 我希望旋转器始终在顶部。唯一 更改为微调器下的内容 在活动中创建一个简单的方法来刷新微调器下方的布局(该微调器将保持不变)。该方法将从微调器上的OnItemSelectedListener集调用。应该是这样的: private void changeAdress(int newSelectedAdress) { // The ImageView and the TextView will be already
微调器中选择项目后,如何显示不同的内容?
我想创建一个带有连锁店位置的微调器
我希望旋转器始终在顶部。唯一
更改为微调器下的内容
在活动中创建一个简单的方法来刷新微调器下方的布局(该微调器将保持不变)。该方法将从微调器上的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) {
}
});
然后按照我上面推荐的方法使用这两个数组:
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.
}
不需要多个图像视图
和文本视图
即使选择了地址,我仍然希望微调器可见并显示所有位置。我希望微调器始终位于顶部。唯一改变的是spinner=1 adressI的spinner1项下的内容在编程中我是noob,因此我在查看代码时,试图了解如何实现我想要的方式。onItemSelected{if int=0->Show Image1,Text1;if int=1->Show Image2;Text2…都在同一个活动中。这就是我想要做的it@CatalinH是,在changeAddress
方法中,您将查看newselectedAddress
参数。如果它是1
您将加载第一个地址,如果它是2
您将加载第二个地址,等等不知道如何存储这些地址,例如,如果您将它们放在一个数组中,那么您只需从该数组中获取索引newselectedAddress
处的项。我对我的答案进行了一些编辑。很抱歉,我仍然迷路了。我编辑了我的问题,并添加了类代码和xml。我在代码中编写了一些我需要的详细信息你能帮我弄清楚吗?弄清楚了。每个int位置都需要一个ImageView和TextView。对于ImageView也需要:img.setBackgroundResource(R.drawable.image);谢谢Luksprog。
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.
}