画廊项目上的longClickable

时间:2013-07-11 16:55:17

标签: java android user-interface android-widget

我想要达到的目的是让用户在图库视图中长按图像以将其带到网站。

到目前为止我所拥有的是这个,但似乎无法解决这个问题....

 .......
 public int getCount() {
    return imageIDs.length;
 .....
 public View getView(int position, View convertView, ViewGroup parent){
    ImageView imageView;
    if (convertView == null){
        imageView = new ImageView(context);
        imageView.setImageResource(imageIDs[position]);
        imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);


    }else{
        imageView = (ImageView) convertView;
    }
    imageView.setBackgroundResource(itemBackground);
    return imageView;

        imageView.setOnLongClickListener(imageIDs[position]){

            boolean onLongClick(int position,View v) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse ("http://www.google.com"));
            startActivity(intent);
            return true;
        }
    {
    }
}

 }

获取此错误

 The method setOnLongClickListener(View.OnLongClickListener) in the type View is not applicable  for the arguments 
 (Integer)

任何帮助将不胜感激!!

1 个答案:

答案 0 :(得分:0)

错误告诉您到底出了什么问题。 imageIDs [position]返回一个int,而setOnLongClickListener则获取一个OnLongClickListener。类似的东西:

imageView.setOnLongClickListener(new OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse ("http://www.google.com"));
        startActivity(intent);
        return true;
    }
});

注意:将OnItemLongClickListener切换为OnLongClickListener