正文

使用內(nèi)置Gallery應(yīng)用程序選擇圖像(2)

Android多媒體開發(fā)高級(jí)編程 作者:(美)艾佛瑞


public class ChoosePicture extends Activity implements OnClickListener {

     ImageView chosenImageView;

     Button choosePicture;

     @Override 

     public void onCreate(Bundle savedInstanceState) {

          super.onCreate(savedInstanceState);

          setContentView(R.layout.main);

     chosenImageView = (ImageView) this.findViewById(R.id.ChosenImageView);

     choosePicture = (Button) this.findViewById(R.id.ChoosePictureButton);

     choosePicture.setOnClickListener(this);

}

隨后是onClick方法,它將響應(yīng)choosePicture按鈕的單擊事件,該按鈕在應(yīng)用程序啟動(dòng)時(shí)顯示,如圖3-1所示。這個(gè)方法創(chuàng)建意圖,其將觸發(fā)Gallery應(yīng)用程序,使其以允許用戶選擇一張圖片的模式啟動(dòng),如圖3-2所示。

     public void onClick(View v) {

          Intent choosePictureIntent = new Intent(Intent.ACTION_PICK,

 android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

          startActivityForResult(choosePictureIntent, 0);


上一章目錄下一章

Copyright ? 讀書網(wǎng) www.afriseller.com 2005-2020, All Rights Reserved.
鄂ICP備15019699號(hào) 鄂公網(wǎng)安備 42010302001612號(hào)