0

私が達成したいのは、ユーザーがギャラリー ビューで画像をロングクリックして Web サイトに移動することです。

私がこれまでに持っているのはこれですが、うまくいかないようです....

 .......
 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 に答える