0
できるだけ明確にしようとします。 私は画像を表示するGridviewを持っています。ユーザーはOnLongClickで複数の画像を選択できます。 onLongClickはアダプタにあります。コードにはonItemSelectedListenerもあり、選択した画像を特定の位置にズームします。 問題は、任意の位置でgridviewをタップした後にonItemSelectedListenerがトリガーされないことです。また、onLongClickを使用すると、OnItemSelectedListenerメソッドとonLongClickListenerメソッドの両方がトリガーされます。以前提供されたソリューションを使用してみましたが、これはonLongClickListenerでtrueを返していましたが、それはどちらも失敗しました。私はここで立ち往生している。ヘルプをいただければ幸いです。 ありがとうございます。グリッドビューでonLongClickを押したときにOnItemSelectedListenerが発生します
gvImages.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
PhotoBeans bean = (PhotoBeans) parent.getItemAtPosition(position);
j = position;
photoUrl = bean.getThumbImageUrl();
Log.e("photoUrl", "" + photoUrl);
zoomImageFromThumb(view, photoUrl);
}
});
//アダプタ
public class ImageAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private ArrayList<PhotoBeans> arrayListPhoto;
public ImageAdapter(ArrayList<PhotoBeans> arrayListPhoto) {
this.arrayListPhoto = arrayListPhoto;
mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return arrayListPhoto.size();
}
@Override
public Object getItem(int position) {
return arrayListPhoto.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View rootView = convertView;
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
rootView = mInflater.inflate(R.layout.custom_gallery_item, null);
holder.imgThumb = (ImageView) rootView.findViewById(R.id.imgThumb);
holder.chkImage = (ImageView) rootView.findViewById(R.id.chkImage);
rootView.setTag(holder);
} else {
holder = (ViewHolder) rootView.getTag();
}
if (arrayListPhoto.get(position).isImageSelected()) {
holder.chkImage.setVisibility(View.VISIBLE);
holder.imgThumb.setAlpha(0.5f);
} else {
holder.chkImage.setVisibility(View.GONE);
holder.imgThumb.setAlpha(1f);
}
holder.imgThumb.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (arrayListPhoto.get(position).isImageSelected()) {
holder.chkImage.setVisibility(View.GONE);
holder.imgThumb.setAlpha(1f);
arrayListPhoto.get(position).setIsImageSelected(false);
} else {
holder.chkImage.setVisibility(View.VISIBLE);
holder.imgThumb.setAlpha(0.5f);
arrayListPhoto.get(position).setIsImageSelected(true);
}
notifyDataSetChanged();
return true;
}
});
Picasso.with(Photos.this)
.load(new File(arrayListPhoto.get(position).getThumbImageUrl()))
.resize(150, 150)
.centerCrop()
.into(holder.imgThumb);
return rootView;
}
}
class ViewHolder {
ImageView imgThumb;
ImageView chkImage;
int id;
}
のようなあなたの活動に、この内のコードを入れて、あなたのコードを入れてください。 –
コードを投稿しました。 – AmeyaG
アダプターにlongclickのコードを書く理由 –