私はリストビューを持っていて、タッチしたときに行(アイテム)の背景色を変更したいだけですが(MotionEvent.ACTION_DOWN)、リストビューのスクロール中にこれを防ぎます。これどうやってするの ?
これがListViewのBaseAdapterです
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
DataHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new DataHolder();
holder.newAppsLayout = (LinearLayout) row.findViewById(R.id.new_apps_layout);
holder.imageView1 = (ImageView) row.findViewById(R.id.imageView1);
row.setTag(holder);
} else {
holder = (DataHolder) row.getTag();
}
Data data = data.get(position);
ImageCacheManager.loadImage(holder.imageView1, item.getIconUrl());
final DataHolder finalHolder = holder;
row.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
finalHolder.newAppsLayout.setBackgroundColor(Color.GRAY);
} else {
finalHolder.newAppsLayout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.content_bg)); }
return false;
}
});
return row;
static class DataHolder {
LinearLayout newAppsLayout;
ImageView imageView1;
}
それは機能しますが、スクロールのためにタッチしている間も機能します。どうすればこれを防ぐことができますか? つまり、スクロールではなく、タッチイベントでのみ機能しますか?
前もって感謝します