相册,多选图片,加号动态显示

来源:互联网 发布:淘宝多少天默认好评 编辑:程序博客网 时间:2024/04/30 17:54

0. onNewIntent(Intent intent) 可以接收到任意跳转到本界面的意图

    显示图片界面的Activity 设置为singleTask 模式。

1.跳转到图片目录 并且携带已经选择几张图片

         //
Intent intent = new Intent();
intent.setClass(this, ImgFileListActivity.class);
Bundle bundle = new Bundle();

bundle.putInt("PictureCount", lists.size());
intent.putExtras(bundle);
startActivity(intent);

  2.显示各个文件夹的目录

         List<HashMap<String, String>> listdata=new ArrayList<HashMap<String,String>>();
Bitmap bitmap[] = null;
if (locallist!=null) {
bitmap=new Bitmap[locallist.size()];
for (int i = 0; i < locallist.size(); i++) {
HashMap<String, String> map=new HashMap<String, String>();
map.put("filecount", locallist.get(i).filecontent.size()+"张图片");
map.put("imgpath", locallist.get(i).filecontent.get(0)==null?null:(locallist.get(i).filecontent.get(0)));
map.put("filename", locallist.get(i).filename);
listdata.add(map);
}
}
listAdapter=new ImgFileListAdapter(this, listdata);
listView.setAdapter(listAdapter);


3. 点击跳转到相应的目录下

        
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Intent intent=new Intent(this,ImgsActivity.class);
Bundle bundle=new Bundle();
bundle.putParcelable("data", locallist.get(arg2));
bundle.putInt("selectpicture", selectP);
intent.putExtras(bundle);
startActivity(intent);
finish();
}

  4.获取到目录下所有图片并且用gridView 显示

接收数据parce

             bundle = getIntent().getExtras();
fileTraversal = bundle.getParcelable("data");

      

// 获取某个相册的所有图片 地址
listsP = fileTraversal.filecontent;
listsRP = new ArrayList<String>();
imgsAdapter = new ImgsAdapter(listsP, ImgsActivity.this);
imgGridView.setAdapter(imgsAdapter);

//单击事件来添加 图片到一个线性布局中 ,并且将图片的地址 加到listsRp集合内

//
for (int i = 0; i < listsP.size(); i++) {
listsBoolean.add(true);
//用布尔类型来标记是否选择过这张图片

        //点击选择图片

imgGridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long arg3) {
String filapath = fileTraversal.filecontent.get(position);
if (selectpicture - select_layout.getChildCount() > 0) {
if (listsRP.size() <= 5) {
if (listsBoolean.get(position) == true) {
listsRP.add(filapath);
listsBoolean.set(position, false);
// 将这张图片添加到线性布局里面
addPictureToLinear(filapath, position);
} else {
ToastLocationUtils.toastLocalUtils(
ImgsActivity.this, "该图片已添加过");
}
} else {
ToastLocationUtils.toastLocalUtils(ImgsActivity.this,
"最多添加6张图片");
}
} else {
ToastLocationUtils.toastLocalUtils(ImgsActivity.this,
"最多选择6张图片");
}
int sPicture = selectpicture-select_layout.getChildCount();
choise_button.setText("(已选择" + select_layout.getChildCount()
+ "张图片)    还可选择(" + sPicture + ")张");
}
});

         //意图将数据集合传回到发帖界面

Intent intent = new Intent(this, MyReportPost.class);
Bundle bundle = new Bundle();
bundle.putStringArrayList("files", listsRP);
intent.putExtras(bundle);
startActivity(intent);

              //集合显示,刷新适配器即可



0 0
原创粉丝点击