xiayan_1983
anglexia
2015-05-19 08:13
采纳率: 50%
浏览 5.8k

android viewpager里面的一张图片长按跳出删除按钮,可以删除这张图片

android viewpager里面的一张图片长按跳出删除按钮,可以删除这张图片
viewpager的填充类如下
protected class SamplePagerAdapter extends PagerAdapter {
private LayoutInflater inflater;
private int position1 = 0;

    SamplePagerAdapter() {
        inflater = getLayoutInflater();


    }

    @Override
    public int getCount() {
        return strDrawables.length;
    }

    @Override
    public View instantiateItem(ViewGroup container, int position) {

        View imageLayout = inflater.inflate(R.layout.item01, null);
        //View imageLayout = inflater.inflate(R.layout.item01, container, false);
        ImageView imageView = (ImageView) imageLayout.findViewById(R.id.img);  //这个为null

        final ProgressBar spinner = (ProgressBar) imageLayout
                .findViewById(R.id.loading);
        position1=position;

        final String imgUrl = strDrawables[position];
        System.out.println("imageLoader = " + imageLoader + "imageUrl = " + imgUrl + "imageView = " + imageView);

        //imageLoader也是null
        imageLoader.displayImage(imgUrl, imageView, options,
                new SimpleImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String imageUri, View view) {
                        spinner.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onLoadingFailed(String imageUri, View view,
                                                FailReason failReason) {
                        String message = null;
                        switch (failReason.getType()) {
                            case IO_ERROR:
                                message = "Input/Output error";
                                break;
                            case DECODING_ERROR:
                                message = "Image can't be decoded";
                                break;
                            case NETWORK_DENIED:
                                message = "Downloads are denied";
                                break;
                            case OUT_OF_MEMORY:
                                message = "Out Of Memory error";
                                break;
                            case UNKNOWN:
                                message = "Unknown error";
                                break;
                        }
                        Toast.makeText(activity_detail.this, message,
                                Toast.LENGTH_SHORT).show();

                        spinner.setVisibility(View.GONE);
                    }

                    @Override
                    public void onLoadingComplete(String imageUri,
                                                  View view, Bitmap loadedImage) {
                        spinner.setVisibility(View.GONE);
                    }
                });
        ((ViewPager) container).addView(imageLayout, 0);
        imageView.setOnLongClickListener(new deleteClickListener());


        return imageLayout;
    }
        //对应图片的位置


    private final class deleteClickListener implements View.OnLongClickListener {
        @Override
        public boolean onLongClick(View v) {
            //获取商品的数量

            showDialog();

            return false;
        }
    }

    private void showDialog()
    {
        inflater = getLayoutInflater();
        View view = inflater.inflate(R.layout.delete_picture, null);
        Button btndel = (Button)view.findViewById(R.id.btndel);
        btndel.setOnClickListener(new ButtonClickListener1());
        new AlertDialog.Builder(activity_detail.this)
                .setView(view)
                .create().show();
    }




    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }


}

    showDialog那个函数就是弹出删除的按钮请大家帮忙看看到底哪里不对

    还是我思路有问题,如果有问题请帮忙给我提供一个思路

    感谢
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • bdmh
    bdmh 2015-05-19 08:21
    已采纳

    你什么问题,能不能弹出来,长按事件能不能触发

    点赞 评论
  • u010514380
    super小靖 2015-05-19 09:59

    有错误还是咋地???

    点赞 评论
  • crazy1235
    月盡天明 2015-05-20 08:32

    没看懂你的问题是 什么????

    点赞 评论
  • yuan_love
    java-缘 2015-05-25 05:16

    到底是什么问题呢,说明白点

    点赞 评论

相关推荐