数组元素

时间:2017-03-30 06:05:19

标签: java android arrays alertdialog

我有以下问题,结果是我有一个适配器类 其中显示了元素列表(可能有照片)

实施例

  • 数组[0]包含照片
  • 数组1不包含照片
  • 数组2包含照片

我的问题是如何在数组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

enter image description here

enter image description here enter image description here

我只是想将一个AlertDialog添加到viewPager元素的位置1

1 个答案:

答案 0 :(得分:0)

创建AlertDialog页面时不要创建或显示ViewPager,而是在选择页面时检查是否需要AlertDialog,然后构建并显示该对话框使用ViewPager.OnPageChangeListenerViewPager.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();
      }
   }
});