A sentimental robot

Spinner 본문

Android Studio

Spinner

GOD03219 2018. 1. 29. 14:32




public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);




Spinner spinner=(Spinner)findViewById(R.id.spinner);

//스피너에 들어갈 데이터(item) 만들기
String []str=new String[]{"ti1","ti2","ti3","ti4"};

//adapter 생성
ArrayAdapter<String>aa=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, str);



spinner.setAdapter(aa);


spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Log.v("eun","position:"+position+" "+parent.getSelectedItem().toString());

@Override
public void onNothingSelected(AdapterView<?> parent) {


}
});
}



}

'Android Studio' 카테고리의 다른 글

Activity transition/intent  (0) 2018.01.30
ListView  (0) 2018.01.29
LinearLayout  (0) 2018.01.12
메소드를 공유하는 위젯  (0) 2018.01.12
익명클래스를 이용해서 이벤트리스너 만들기  (0) 2018.01.11