我有以下问题,结果是我有一个适配器类 其中显示了元素列表(可能有照片)
实施例
我的问题是如何在数组1中显示一个对话警报?
他试过,设置alertDialog,但它总是在数组内放置两次位置[0] 我只希望能在阵列位置1
显示对话警报有人可以帮帮我吗。
displayImage = (TouchImageView) viewLayout.findViewById(R.id.imgDisplay);
final ChatMessage myMessage = pathsLocal.get(position);
AttachmentObject attachmentObject = null;
switch (myMessage.getMessageType()) {
case IMAGE:
attachmentObject = myMessage.getFullsizePhoto();
break;
case VIDEO:
attachmentObject = myMessage.getAttachment("video");
break;
}
File fileImage = new File(attachmentObject.localPath);
if (fileImage.exists()) {
Uri uri = Uri.fromFile(fileImage);
Picasso.with(ApplicationSingleton.getInstance())
.load(uri)
.into(displayImage);
} else {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(activityAdapter);
alertDialog.setTitle(R.string.title);
alertDialog.setMessage(R.string.subtitle);
alertDialog.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alertDialogBuilder1 = alertDialog.create();
alertDialog.show();
}
}
我想做的只是位置1内的AlertDialog条目,而不影响viewPager的元素0和2
我只是想将一个AlertDialog添加到viewPager元素的位置1
答案 0 :(得分:0)
创建AlertDialog
页面时不要创建或显示ViewPager
,而是在选择页面时检查是否需要AlertDialog
,然后构建并显示该对话框使用ViewPager.OnPageChangeListener或ViewPager.SimpleOnPageChangeListener
myViewPager.addOnPageChangeListener(new SimpleOnPageChangeListener() {
void onPageSelected(int position) {
boolean shouldIShowAlert = // implement this
if (shouldIShowAlert) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(activityAdapter);
alertDialog.setTitle(R.string.title);
alertDialog.setMessage(R.string.subtitle);
alertDialog.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alertDialogBuilder1 = alertDialog.create();
alertDialog.show();
}
}
});