SPRING :: NOTE

[android] 한 메소드로 Spinner 여러개 사용하기 본문

Development Language/JAVA · ANDROID

[android] 한 메소드로 Spinner 여러개 사용하기

RAYZIE 2016. 6. 10. 14:23
반응형

<pre><code class="java">public class Info extends Activity {

 

    ArrayAdapter<CharSequence> adspin;

 

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.info);

 

        spinner((Spinner)findViewById(R.id.spinner1) ,R.array.open);

       

       

       

    }

 

    public void spinner(Spinner sp, int textArrayResId) {

       

        adspin = ArrayAdapter.createFromResource(this, textArrayResId,

                android.R.layout.simple_spinner_item);

        adspin.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

 

 

        sp.setAdapter(adspin);

        sp.setOnItemSelectedListener(new OnItemSelectedListener() {

 

            @Override

            public void onItemSelected(AdapterView<?> arg0, View arg1,

                    int position, long arg3) {

                // TODO Auto-generated method stub

                Toast.makeText(Info.this,

                        adspin.getItem(position) + "을/를 선택 했습니다.",

                        Toast.LENGTH_SHORT).show();

            }

 

            @Override

            public void onNothingSelected(AdapterView<?> arg0) {

                // TODO Auto-generated method stub

 

            }

        });

    }

 

}

</code></pre>

반응형
Comments