android拍照并给照片添加备注,以GridView显示
附完整代码,此代码只实现功能,美观及其它不考虑(*^__^*)
为秭归等地区用户提供了全套网页设计制作服务,及秭归网站建设行业解决方案。主营业务为网站设计、成都网站设计、秭归网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
java代码:
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.provider.MediaStore;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Intent;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private ImageView iv_img;
private TextView tv_remark;
private AlertDialog dialog;
private EditText et_remark;
private List
private List
private GridView gv;
private MyAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
initData();
}
private void initView() {
gv = (GridView) findViewById(R.id.gv_show);
}
private void initData() {
adapter = new MyAdapter();
gv.setAdapter(adapter);
}
private class MyAdapter extends BaseAdapter {
@Override
public int getCount() {
return lb.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = View.inflate(getApplicationContext(), R.layout.gv_item,
null);
iv_img = (ImageView) view.findViewById(R.id.iv_img);
tv_remark = (TextView) view.findViewById(R.id.tv_remark);
Bitmap bm = lb.get(position);
String remark = ls.get(position);
iv_img.setImageBitmap(bm);
tv_remark.setText(remark);
return view;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_paizhao:
onRemark();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
// 拍照Activity保存图像数据的key是data,返回的数据类型是Bitmap对象
Bitmap cameraBitmap = data.getExtras().getParcelable("data");
// 将拍到的照片存放于集合中
lb.add(cameraBitmap);
initData();
}
super.onActivityResult(requestCode, resultCode, data);
}
/**
* 给照片添加备注信息
*/
public void onRemark() {
AlertDialog.Builder builder = new Builder(MainActivity.this);
dialog = builder.create();
View view = View
.inflate(getApplicationContext(), R.layout.dialog_remark, null);
et_remark = (EditText) view.findViewById(R.id.et_remark);
Button bt_ok = (Button) view.findViewById(R.id.bt_ok);
Button bt_no = (Button) view.findViewById(R.id.bt_no);
bt_ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String remark = et_remark.getText().toString().trim();
if (TextUtils.isEmpty(remark)) {
Toast.makeText(getApplicationContext(), "添点备注吧~~~⊙﹏⊙‖∣",
2000).show();
} else {
// 将备注信息添加到集合中
ls.add(remark);
// 调用系统照相机
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 1);
dialog.dismiss();
}
}
});
bt_no.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.setView(view, 0, 0, 0, 0);
dialog.show();
}
}
activity_main.xml布局:
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > android:id="@+id/gv_show" android:layout_width="fill_parent" android:layout_height="wrap_content" android:numColumns="2" />
dialog_remark.xml布局:
android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" > android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/beizhu" android:textColor="@android:color/black" android:textSize="18dip" /> android:id="@+id/et_remark" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="20dip" android:textColor="@android:color/black" /> android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > android:layout_width="fill_parent" android:layout_height="wrap_content" >
gv_item.xml布局:
android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" > android:id="@+id/iv_img" android:layout_width="wrap_content" android:layout_height="wrap_content" /> android:id="@+id/tv_remark" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
menu文件下的main.xml布局:
标题名称:android拍照并给照片添加备注,以GridView显示
网站地址:http://pwwzsj.com/article/igpsep.html