package com.me.nereo.multiimageselector;import android.content.Intent;import android.support.v7.app.ActionBarActivity;import android.os.Bundle;import android.text.TextUtils;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.EditText;import android.widget.RadioGroup;import android.widget.TextView;import java.util.ArrayList;import com.me.nereo.multiimageselector.R;import com.me.nereo.selector.MultiImageSelectorActivity;public class MainActivity extends ActionBarActivity { private static final int REQUEST_IMAGE = 2; private TextView mResultText; private RadioGroup mChoiceMode, mShowCamera; private EditText mRequestNum; private ArrayList<String> mSelectPath; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mResultText = (TextView) findViewById(R.id.result); mChoiceMode = (RadioGroup) findViewById(R.id.choice_mode); mShowCamera = (RadioGroup) findViewById(R.id.show_camera); mRequestNum = (EditText) findViewById(R.id.request_num); mChoiceMode.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int checkedId) { if(checkedId == R.id.multi){ mRequestNum.setEnabled(true); }else{ mRequestNum.setEnabled(false); mRequestNum.setText(""); } } }); findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int selectedMode = MultiImageSelectorActivity.MODE_MULTI; if(mChoiceMode.getCheckedRadioButtonId() == R.id.single){ selectedMode = MultiImageSelectorActivity.MODE_SINGLE; }else{ selectedMode = MultiImageSelectorActivity.MODE_MULTI; } boolean showCamera = mShowCamera.getCheckedRadioButtonId() == R.id.show; int maxNum = 9; if(!TextUtils.isEmpty(mRequestNum.getText())){ maxNum = Integer.valueOf(mRequestNum.getText().toString()); } Intent intent = new Intent(MainActivity.this, MultiImageSelectorActivity.class); // 是否显示拍摄图片 intent.putExtra(MultiImageSelectorActivity.EXTRA_SHOW_CAMERA, showCamera); // 最大可选择图片数量 intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_COUNT, maxNum); // 选择模式 intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_MODE, selectedMode); // 默认选择 if(mSelectPath != null && mSelectPath.size()>0){ intent.putExtra(MultiImageSelectorActivity.EXTRA_DEFAULT_SELECTED_LIST, mSelectPath); } startActivityForResult(intent, REQUEST_IMAGE); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(requestCode == REQUEST_IMAGE){ if(resultCode == RESULT_OK){ mSelectPath = data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT); StringBuilder sb = new StringBuilder(); for(String p: mSelectPath){ sb.append(p); sb.append("n"); } mResultText.setText(sb.toString()); } } } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }
推荐整理分享照片选择器 multiimageselector(选择照片的快捷键),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:照片选取,图片选择器,照片选取,照片选片系统,图片选择器 android,照片选择器不可用,照片选片系统,图片选择器,内容如对您有帮助,希望把文章链接给更多的朋友!
}
Demo实例
Android 退出整个应用程序 三步走1、建立一个JAVA类importjava.util.LinkedList;importjava.util.List;importandroid.app.Activity;importandroid.app.Application;publicclassSysApplicationextendsApplication{privateListActivity
记录 "心跳机制" 相关问题 记录心跳机制相关问题论坛里碰到一个问题,记录一下。一、心跳分为两种,第一种是客户端发起的心跳,第二种是服务端发起的心跳。客户端发起的
Android点滴---drawable粘贴图片后 R文件报错,解决 今天往项目中粘贴使用图片时,刚把图片粘贴到Drawable文件中,就报错了,看了错误提示发现是我起文件名时粗心,写了一个大写字母!如果你是这种情