如何更改微调的背景图片? [英] How to change spinner background image?

查看:109
本文介绍了如何更改微调的背景图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的机器人,我用微调的背景图片。微调器包含四个值,而且每一个都有images.If我点击微调值,图像将在微调背景下进行更改。请帮助我,我怎么可以改变背景图像时的微调值被改变了吗?

Hi i am new to android,I am using spinner background image. The spinner contains four values, and each one has images.If i click the spinner values, the images will be changed in the spinner background. Please help me how can i change the background image when the spinner value is changed?

推荐答案

给ID给父(线性或相对)的main.xml中的文件布局 并在Java文件中,如果您的微调的四个值是水星,金星,地球,火星, 然后在Onselected的ItemListener,把code这样

Give Id to the parent (Linear or relative) layout of your main.xml file and in the java file,if the four values of your spinner is Mercury,Venus,Earth,Mars, then in the Onselected itemlistener,put code like this

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);
      }
}

这篇关于如何更改微调的背景图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆