How to change spinner background image?
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?
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);
}
}
精彩评论