图片选择器

时间:2019-03-10 07:16:44
【文件属性】:

文件名称:图片选择器

文件大小:5.87MB

文件格式:RAR

更新时间:2019-03-10 07:16:44

ImageSelect

package com.example.administrator.application; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.GridView; import android.widget.TextView; import android.widget.Toast; import com.example.administrator.application.activity.CCwantPhotoBrowserActivity; import com.example.administrator.application.activity.CCwantSelectAlbumActivity; import com.example.administrator.application.adapter.CCwantPublishAdapter; import java.io.Serializable; import java.util.ArrayList; import java.util.List; public class Main2Activity extends Activity { /** * 打开相册选择activity */ private final int OPEN_SELECT_ALBUM=1; /** * 打开图片浏览器activity */ private final int OPEN_PHOTO_BROWSER=2; /** * 你选择的所有图片路径 */ private List mData=new ArrayList(); private GridView mGrvContent; private CCwantPublishAdapter mAdapter; private TextView mTxtSend; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); mAdapter=new CCwantPublishAdapter(this,mData); mGrvContent=(GridView)findViewById(R.id.grv_content); mGrvContent.setAdapter(mAdapter); mGrvContent.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { //如果点击了+则打开相册选择器,否则打开相片浏览界面 if(position==mAdapter.getMaxPosition()-1){ Intent intent=new Intent(Main2Activity.this,CCwantSelectAlbumActivity.class); startActivityForResult(intent, OPEN_SELECT_ALBUM); }else{ Intent intent=new Intent(Main2Activity.this,CCwantPhotoBrowserActivity.class); intent.putExtra("CCwantPhotoList",(Serializable) mData); intent.putExtra("CCwantPhotoPosition",(Serializable)position); startActivityForResult(intent, OPEN_PHOTO_BROWSER); } } }); mTxtSend=(TextView)findViewById(R.id.txt_send); mTxtSend.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < mData.size(); i++) { sb.append(mData.get(i) + "\n"); } Toast.makeText(getApplicationContext(), "" + sb.toString(), Toast.LENGTH_SHORT).show(); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //处理选择图片后的返回值 if(requestCode==OPEN_SELECT_ALBUM){ if (resultCode == RESULT_OK) { Bundle bundle = data.getExtras(); List list=new ArrayList(); list.addAll(mData); list.addAll(bundle.getStringArrayList("result")); mData.clear(); mData.addAll(list); mAdapter.notifyDataSetChanged(); } } //处理图片浏览的返回值 if(requestCode==OPEN_PHOTO_BROWSER){ if (resultCode == RESULT_OK) { Bundle bundle = data.getExtras(); List list=bundle.getStringArrayList("result"); mData.clear(); mData.addAll(list); mAdapter.notifyDataSetChanged(); } } } }


网友评论