附完整代碼,此代碼只實現(xiàn)功能,美觀及其它不考慮(*^__^*)
為秭歸等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及秭歸網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為網(wǎng)站設(shè)計、成都網(wǎng)站設(shè)計、秭歸網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
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<Bitmap> lb = new ArrayList<Bitmap>();
private List<String> ls = new ArrayList<String>();
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保存圖像數(shù)據(jù)的key是data,返回的數(shù)據(jù)類型是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);
// 調(diào)用系統(tǒng)照相機
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布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<GridView
android:id="@+id/gv_show"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:numColumns="2" />
</LinearLayout>
dialog_remark.xml布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/beizhu"
android:textColor="@android:color/black"
android:textSize="18dip" />
<EditText
android:id="@+id/et_remark"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:textColor="@android:color/black" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/bt_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="20dip"
android:text="@string/ok" />
<Button
android:id="@+id/bt_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="20dip"
android:text="@string/no" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
gv_item.xml布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/iv_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_remark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
menu文件下的main.xml布局:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_paizhao"
android:orderInCategory="100"
android:showAsAction="ifRoom|withText"
android:icon="@android:drawable/ic_menu_add"/>
</menu>
網(wǎng)頁題目:android拍照并給照片添加備注,以GridView顯示
瀏覽路徑:http://www.rwnh.cn/article48/igpsep.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、面包屑導(dǎo)航、外貿(mào)建站、品牌網(wǎng)站設(shè)計、軟件開發(fā)、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)