package kyy.dbw.test3;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
public class DataBWT3 extends Activity {
private Gallery g;
static final int IMGS[] = {R.drawable.a01,
R.drawable.a02,
R.drawable.a03,
R.drawable.a04,
R.drawable.a05,
R.drawable.a06,
R.drawable.a07,
R.drawable.a08,
R.drawable.a09,
R.drawable.a10,
R.drawable.a11,
R.drawable.a12
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
g = (Gallery)findViewById(R.id.Gallery01); // VIEW
g.setAdapter(new UserAdapter(this));
g.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long arg3) {
Toast.makeText(DataBWT3.this, "선택 인덱스 : " + position, 0).show();
}
});
}
}
class UserAdapter extends BaseAdapter{ // Controller
private Context c;
private ImageView iv;
UserAdapter(){
}
UserAdapter(DataBWT3 c){
this.c = c;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return DataBWT3.IMGS.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return DataBWT3.IMGS[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if(convertView == null){
iv = new ImageView(c);
iv.setLayoutParams(new Gallery.LayoutParams(120, 150));
iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
//iv.setScaleType(ImageView.ScaleType.FIT_XY); //크기 고정 옵션
iv.setPadding(5, 5, 15, 5);
}else{
iv = (ImageView)convertView;
}
iv.setImageResource(DataBWT3.IMGS[position]);
return iv;
}
}
'스마트폰 > 안드로이드' 카테고리의 다른 글
웹 소스 찍기 (0) | 2011.05.13 |
---|---|
데이터 바인딩4 공부 (0) | 2011.05.13 |
데이터 바인딩2 공부 (0) | 2011.05.13 |
데이터 바인딩1 공부 (0) | 2011.05.13 |
anim2(애니메이션) 공부 (0) | 2011.05.13 |