package com.example.it.myapplication9_6;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("스피너 테스트");
final String[] movie = { "쿵푸팬더", "짱구는 못말려", "아저씨",
"아바타", "대부", "국가대표",
"토이스토리3", "마당을 나온 암탉", "죽은 시인의 사회",
"서유기" };
final Integer [] movieImg = {R.drawable.mov21,R.drawable.mov22,R.drawable.mov23,
R.drawable.mov24,R.drawable.mov25,R.drawable.mov26,
R.drawable.mov27,R.drawable.mov28,R.drawable.mov29,
R.drawable.mov30};
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<String> adapter ;
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, movie);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
ImageView imgView1 = (ImageView) findViewById(R.id.imgView1);
imgView1.setImageResource(movieImg[position]);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/imgView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
android - 배터리 상태 체크, BroadcastReceiver, onReceive (0) |
2018.11.11 |
android - 음악플레이어, 서비스 (service), onStartCommand (0) |
2018.11.11 |
android - Adapter, Gallery, custom toast, inflate (0) |
2018.11.10 |
android - Adapter, GridView, AlertDialog (0) |
2018.11.10 |
android - Adapter, ListView, arraylist 항목추가, 삭제 (0) |
2018.11.10 |