开发者

How can i use a switch with a spinner?

开发者 https://www.devze.com 2023-01-15 05:31 出处:网络
so i started android programming like a month ago, and i\'ve got a probleme today. The thing i want to do is : From a Item in the Spinner, when i select it there is a Text View changing on the back.

so i started android programming like a month ago, and i've got a probleme today.

The thing i want to do is : From a Item in the Spinner, when i select it there is a Text View changing on the back.

    spin.setAdapter(adapter_city);
    spin.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent,开发者_如何学运维 View v, int position, long id) {

    switch(v.getId()){

        case R.string.Paris : description.setText("blah blah");
    }

}

and i would like the description fit with the resource.

Paris is in a xml called "cities", it's a value xml. Thank you.


If you call parent.getItemAtPosition(position), it will give you back to actual String you put in to the spinner. Then you can compare this with getString(R.string.Paris) to see if they are the same, and act accordingly. You cannot switch on a String in Java, so you just have to write a some if statements.

0

精彩评论

暂无评论...
验证码 换一张
取 消