0

嗨,我是 android 新手,我正在使用微调器背景图像。微调器包含四个值,每个都有图像。如果我单击微调器值,图像将在微调器背景中更改。请帮助我在更改微调器值时如何更改背景图像?

4

1 回答 1

0

将 ID 赋予 main.xml 文件和 java 文件的父(线性或相对)布局,如果微调器的四个值是 Mercury、Venus、Earth、Mars,则在 Onselected itemlistener 中输入如下代码

public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
      Toast.makeText(parent.getContext(), "The planet is " +
          parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
      if(parent.getItemAtPosition(pos).toString().equalsIgnoreCase("Mercury"))
      {
          ll1.setBackgroundResource(R.drawable.java_j2me);
      }
      if(parent.getItemAtPosition(pos).toString().equalsIgnoreCase("Venus"))
      {
          ll1.setBackgroundResource(R.drawable.image);
      }
      if(parent.getItemAtPosition(pos).toString().equalsIgnoreCase("Earth"))
      {
          ll1.setBackgroundResource(R.drawable.javaandroid);
      }
      if(parent.getItemAtPosition(pos).toString().equalsIgnoreCase("Mars"))
      {
          ll1.setBackgroundResource(R.drawable.party);
      }
}
于 2011-04-29T09:31:02.877 回答