大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺
public class MainActivity extendsAppCompatActivity {int REQUEST_CODE = 0;privateNineGridImageView ngiv;private ArrayListphotos;privateDialog dialog;privatecn.com.jwtimes.www.jwtimes.mAdapter mAdapter1;
@Overrideprotected voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv=findViewById(R.id.tv);
ngiv=findViewById(R.id.ngiv);
tv.setOnClickListener(newView.OnClickListener() {
@Overridepublic voidonClick(View v) {
PhotoPickerIntent intent= new PhotoPickerIntent(MainActivity.this);
intent.setPhotoCount(9);
intent.setShowCamera(true);
startActivityForResult(intent, REQUEST_CODE);
}
});
}
@Overrideprotected void onActivityResult(int requestCode, intresultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);if (resultCode == RESULT_OK && requestCode ==REQUEST_CODE) {if (data != null) {
photos=data.getStringArrayListExtra(PhotoPickerActivity.KEY_SELECTED_PHOTOS);
ngiv.setAdapter(mAdapter);
ngiv.setImagesData(photos);
}
}
}private NineGridImageViewAdapter mAdapter = new NineGridImageViewAdapter() {
@Overrideprotected void onDisplayImage(Context context, ImageView imageView, finalString url) {
Glide.with(context)
.load(url)
.into(imageView);
}
@OverrideprotectedImageView generateImageView(Context context) {return super.generateImageView(context);
}
@Overrideprotected void onItemImageClick(Context context, int index, ListphotoList) {
showBigPicture(context, photos, index);
}
};private void showBigPicture(Context context, final ArrayList photos, final intindex) {
dialog= newDialog(context, R.style.MyDialog);
View contentView= View.inflate(context, R.layout.dialog_tip, null);final ViewPager vp =(ViewPager) contentView.findViewById(R.id.vp);
ImageView ivDelete=(ImageView) contentView.findViewById(R.id.ivDelete);
mAdapter1= new mAdapter(this, photos, dialog);
vp.setAdapter(mAdapter1);
vp.setCurrentItem(index);
ivDelete.setOnClickListener(newView.OnClickListener() {
@Overridepublic voidonClick(View v) {int currentItem =vp.getCurrentItem();
Iterator sListIterator =photos.iterator();while(sListIterator.hasNext()) {
String e=sListIterator.next();if(e.equals(photos.get(currentItem))) {
sListIterator.remove();
mAdapter1.notifyDataSetChanged();break;
}
}
}
});
dialog.setOnDismissListener(newDialogInterface.OnDismissListener() {
@Overridepublic voidonDismiss(DialogInterface dialog) {
ngiv.setAdapter(MainActivity.this.mAdapter);
ngiv.setImagesData(photos);
}
});
dialog.setContentView(contentView);
dialog.setCancelable(true);
dialog.getWindow().setLayout(
getScreenWidth(),
getScreenHeight());
dialog.show();
}public intgetScreenWidth() {
Resources resources=getResources();returnresources.getDisplayMetrics().widthPixels;
}public intgetScreenHeight() {
Resources resources=getResources();returnresources.getDisplayMetrics().heightPixels;
}
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/190791.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...