1.온아이템셀렉트 리스너 구현에 관하여 질문 드립니다.
2.제가 인텐드로 넘기는 작업을 하고 싶은데.. 
3.막히는 부분이..
4.   CharSequence name;
5.   name = adspin.getItem(position);
6.   if(name =="사과" ){
7.여기서 어떻게 구현을 해야 할지.. getItem??//먼지도 잘모르겠고!! 어떻게 구현을 해야 할까요??
8.전문가님 도움 청합니다!!
view source
print?
01.package Dong.ChoProfile;
02.import android.app.Activity;
03.import android.os.Bundle;
04.import android.view.View;
05.import android.widget.AdapterView;
06.import android.widget.ArrayAdapter;
07.import android.widget.Spinner;
08.import android.widget.Toast;
09.import android.widget.AdapterView.OnItemClickListener;
10.import android.widget.AdapterView.OnItemSelectedListener;
11.public class sub6_04_spinner extends Activity{
12.   
13. ArrayAdapter<CharSequence> adspin;
14. Spinner spinner;
15. public void onCreate(Bundle savedInstanceState){
16.  super.onCreate(savedInstanceState);
17.  setContentView(R.layout.sub6_04_spinner);
18.   
19. spinner = (Spinner)findViewById(R.id.spniner);
20. spinner.setPrompt("선택하세요");//메뉴
21.   
22. adspin = ArrayAdapter.createFromResource(this,R.array.fruits,android.R.layout.simple_spinner_item);
23. adspin.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
24. spinner.setAdapter(adspin);
25.   
26.   
27. spinner.setOnItemSelectedListener(click);
28. }
29.   
30. OnItemSelectedListener click = new OnItemSelectedListener() {
31.  @Override
32.  public void onItemSelected(AdapterView<?> parent, View view, int position,
33.    long id) {
34.   // TODO Auto-generated method stub
35.   CharSequence name;
36.   name = adspin.getItem(position);
37.   if(name.equals"사과" ){
38.  Intent intent = new Intent(sub6_04_spinner.this,sub6_05.class);
39.  startActivity(intent);
40.   }else if(name.equals"복숭아"){
41.      Toast.makeText(sub6_04_spinner.this, "복숭아냐?", Toast.LENGTH_LONG).show();
42.  Intent intent = new Intent(sub6_04_spinner.this,sub6_05.class);
43.  startActivity(intent);
44. }
45.     
46.  }
47.  @Override
48.  public void onNothingSelected(AdapterView<?> parent){
49.   // TODO Auto-generated method stub
50.     
view source
print?
1.arrays.xml
view source
print?
1. 
view source
print?
1.<?xml version="1.0" encoding="utf-8"?>
2.<resources>
3. <string-array name="fruits">
4. <item>사과</item>
5. <item>복숭아</item>
6. <item>참외</item>
7. </string-array>
8.</resources>


 

2011.03.29 10:18:41
신의경지
<meta charset="utf-8">
잘 구현이 된것 같기는한데 문제는 if(name =="사과") 이부분인데요 if (name.equals("사과")) 요렇게 구현하셔야합니다.
오브젝트의 스트링을 비교할때 그냥 ==으로 하게되면 주소값을 비교하게 됩니다그러니 리콜 함수를 써야 제대로스트링을 비교   있게 되는거죠.
YOUR COMMENT IS THE CRITICAL SUCCESS FACTOR FOR THE QUALITY OF BLOG POST