private LinearLayout layout;
private Button button;
private ImageView image;

private int REQ_IMAGE_SELECT= 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);

layout = new LinearLayout(this);
button = new Button(this);
image = new ImageView(this);

layout.setOrientation(LinearLayout.VERTICAL);

button.setText("열기");
button.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,50));
button.setOnClickListener(this);

image.setLayoutParams(new LinearLayout.LayoutParams(200,200));

setContentView(layout);
layout.addView(image);
layout.addView(button);

}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==button){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent ,REQ_IMAGE_SELECT);
}
}
protected void onActivityResult(int requestCode, int resultCode,Intent data){
if(resultCode == Activity.RESULT_OK){
try{
Uri uri = data.getData();
image.setImageURI(uri);
}
catch(Exception e){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent ,REQ_IMAGE_SELECT);
}
}
super.onActivityResult(requestCode, resultCode, data);
}
}

 

출처:http://www.androidside.com/plugin/mobile/board.php?bo_table=B49&wr_id=42333 

 

Posted by 90002
이전버튼 1 2 3 4 5 6 7 8 9 10 이전버튼

블로그 이미지
90002

공지사항

Yesterday6
Today8
Total125,261

최근에 달린 댓글

최근에 받은 트랙백

글 보관함