3

我正在使用以下代码触发单击图库中的图像

                holder.imgPostImagesGallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                    //handle clicks
                    @Override
                    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                        System.out.println("Iamge adapter clicked");
                        /*Show ImageViewerfragment*/
                        Intent intent = new Intent(getActivity(), ImagePagerActivity.class);
                        //Generate Image Array first
                        String[] urls=new String[1];
                        urls[0]=feedsTableList.get(position).post_content.images.get(position).toString();
                        intent.putExtra(Extra.IMAGES, urls);
                        intent.putExtra(Extra.IMAGE_POSITION, 0);
                        startActivity(intent);  
                    }                       
                });

图像适配器代码

public class ImageAdapter extends BaseAdapter {
    public ArrayList<String> images;
    private Context mContext;       
    public ImageAdapter(Context c,ArrayList<String> arrayImages) {
        mContext = c;
        images=arrayImages;
    }

    public int getCount() {
        return images.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    //http://www.edumobile.org/android/android-development/image-gallery-example-in-android/
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView(mContext);
        imageView.setLayoutParams(new Gallery.LayoutParams(320, 320));          
        imageView.setBackgroundResource(R.drawable.black_button);
        imageLoader.displayImage(images.get(position), imageView, options);
        //Add tap listeners
        imageView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

            }
        });
        return imageView;

    }



}

图库工作正常,但单击/点击图像时没有任何反应。

而且,我似乎在画廊滚动方面遇到了问题,它似乎并不正确。滚动滞后,有时根本不滚动。我将它与 SlidingMenu 库一起使用。

更新

正如 mukesh 指出的那样,我错过了 2 个点击事件。但是删除它们也无济于事;但添加我自己的 clicklistener 有帮助

//click listener for gallery
private class galleryPhotoClickListener implements OnItemClickListener{    
    private Context context;

    public galleryPhotoClickListener(Context context){
        this.context = context;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        Intent intent = new Intent(getActivity(), ImagePagerActivity.class);
        //Generate Image Array first
        String[] urls=(String[]) feedsTableList.get(position).post_content.images.toArray();
        urls[0]=feedsTableList.get(position).post_content.images.get(position).toString();
        intent.putExtra(Extra.IMAGES, urls);
        intent.putExtra(Extra.IMAGE_POSITION, 0);
        startActivity(intent);  

    }

}   
4

1 回答 1

3

只使用一个 1 或 2

1.  holder.imgPostImagesGallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                    //handle clicks
                    @Override
                    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                        System.out.println("Iamge adapter clicked");
                        /*Show ImageViewerfragment*/
                        Intent intent = new Intent(getActivity(), ImagePagerActivity.class);
                        //Generate Image Array first
                        String[] urls=new String[1];
                        urls[0]=feedsTableList.get(position).post_content.images.get(position).toString();
                        intent.putExtra(Extra.IMAGES, urls);
                        intent.putExtra(Extra.IMAGE_POSITION, 0);
                        startActivity(intent);  
                    }                       
                });



    or



  2. imageView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                }
            });
于 2012-10-12T03:31:08.603 回答