adv_sdcard_image_upload.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" android:weightSum="1">
<TextView android:id="@+id/txtv_title" android:text="本地400电话 图片添加" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content"></TextView>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:gravity="center" android:layout_weight="0.29">
<Button android:text="选择" android:id="@+id/adv_btn_xuanze" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

<Button android:text="提交" android:id="@+id/adv_btn_tijiao" android:layout_marginLeft="18dp" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="返回" android:id="@+id/adv_btn_fanhui" android:layout_marginLeft="18dp" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout2" android:layout_width="match_parent" android:layout_weight="0.22">
<TextView android:text="任务名称:" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/editText1">
<requestFocus></requestFocus>
</EditText>
</LinearLayout>
<ImageView android:layout_gravity="center_horizontal" android:src="@drawable/clickbutttonstyle"
android:id="@+id/adv_img_show" android:layout_width="302dp" android:layout_height="284dp"></ImageView>

</LinearLayout>

adv_sdcard_image_upload.java

package adv.activity;

import java.io.FileNotFoundException;

import frame.hrxcCall.R;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class adv_sdcard_image_upload extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.adv_sdcard_image_upload);
init();

}

/**
* 初始化方法 http://www.my400800.cn
*/
private void init() {
// 事件注册start
// 选择
Button adv_btn_xuanze = (Button) findViewById(R.id.adv_btn_xuanze);
// 提交
Button adv_btn_tijiao = (Button) findViewById(R.id.adv_btn_tijiao);
// 返回
Button adv_btn_fanhui = (Button) findViewById(R.id.adv_btn_fanhui);

// 返回按钮按下处理事件
adv_btn_fanhui.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
finish();// 这个是关键

}
});

// 事件注册end
adv_btn_xuanze.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
Intent intent = new Intent();
/* 开启Pictures画面Type设定为image */
intent.setType("image/*");
/* 使用Intent.ACTION_GET_CONTENT这个Action */
intent.setAction(Intent.ACTION_GET_CONTENT);
/* 取得相片后返回本画面 */
startActivityForResult(intent, 1);

}
});

// /* 开启Pictures画面Type设定为image */
// intent.setType("image/*");
// /* 使用Intent.ACTION_GET_CONTENT这个Action */
// intent.setAction(Intent.ACTION_GET_CONTENT);
// /* 取得相片后返回本画面 */
// startActivityForResult(intent, 1);
}

/**
* 文件选取完成回调函数
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Uri uri = data.getData();
Log.e("uri", uri.toString());
ContentResolver cr = this.getContentResolver();
try {
Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri));
ImageView adv_img_show = (ImageView) findViewById(R.id.adv_img_show);
/* 将Bitmap设定到ImageView */
adv_img_show.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
Log.e("Exception", e.getMessage(),e);
Toast.makeText(getApplicationContext(), "选择文件没有发现", Toast.LENGTH_LONG).show();
}
}
super.onActivityResult(requestCode, resultCode, data);
}

}

效果:

更多相关文章

  1. Android的Handler机制详解2_native
  2. FregClient和FregServer进程间通信
  3. Android事件分发机制详解:史上最全面、最易懂
  4. 简单明了的分析Android触摸事件,看完再也不纠结了
  5. 简单明了的分析Android触摸事件,看完再也不纠结了
  6. Android事件分发机制详解:史上最全面、最易懂
  7. Android事件分发机制详解:史上最全面、最易懂(转发)
  8. Android(安卓)DEV : setOnClickListener() vs. android:onClick
  9. Android(安卓)事件分发机制

随机推荐

  1. HTML课堂笔记-0704
  2. Android(安卓)NDK开发之旅36--FFmpeg音视
  3. Android(安卓)Mms专题之:PDU介绍
  4. Android,对话框定时自动关闭的实现
  5. 关于android设备管理器的一些分析
  6. Android: 用jni 获取MAC地址
  7. Android(安卓)屏幕适配:最全面的解决方案
  8. Android(安卓)水波纹点击效果(Ripple Eff
  9. Windows环境下Android(安卓)NDK环境搭建
  10. android apk版本更新