0

我想要实现的是让用户长按图库视图中的图像以将他们带到网站。

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

 .......
 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)

任何帮助将不胜感激!!

4

1 回答 1

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

于 2013-07-11T17:06:00.550 回答