TouchEvent:ACTION_DOWN但指针已经关闭。可能缺少先前手势的ACTION_UP

时间:2014-06-29 03:20:31

标签: android

我在做什么 ::

  • 我使用listview进行显示,其中第一行是自定义 xml和第二行是map-widget
  • 我正在使用mapquest api&我想相同的功能适用 谷歌地图也
  • 在地图中我显示了两个地图标记和onclick我显示了 该标记(位置)的详细信息

发生了什么 ::

  • 我能够显示第一个地图标记的详细信息 时间
  • 但是当我立即点击第二个标记时,我无法做到 检测点击事件

我在logcat中获得了msg ::

06-28 23:15:00.143: D/InputEventConsistencyVerifier(3373): TouchEvent: ACTION_DOWN but pointers are already down.  Probably missing ACTION_UP from previous gesture.

代码 :: AdpBufLocation.java

public class AdpBufLocation extends BaseAdapter{

    Context mContext;
    List<Map<String,CharSequence>> mListLayoutData=new ArrayList<Map<String,CharSequence>>();

    private static final int TYPE_ITEM = 0;
    private static final int TYPE_OTHER_LAYOUT = 1;
    private static final int TYPE_MAX_COUNT = TYPE_OTHER_LAYOUT + 1;
    AnnotationView annotation;


    private LayoutInflater mInflater;

    private TreeSet<Integer> mOtherLayoutFlag = new TreeSet<Integer>();

    public AdpBufLocation(Context _mContext) {
        mContext=_mContext;
        mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    }

    public void addListLayoutItem(final Map<String, CharSequence> item) {
        mListLayoutData.add(item);
        notifyDataSetChanged();
    }

    public void addOtherLayoutItem(final Map<String, CharSequence> item) {
        mListLayoutData.add(item);
        // save separator position
        mOtherLayoutFlag.add(mListLayoutData.size() - 1);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return mListLayoutData.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int getItemViewType(int position) {
        return mOtherLayoutFlag.contains(position) ? TYPE_OTHER_LAYOUT : TYPE_ITEM;
    }

    @Override
    public int getViewTypeCount() {
        return TYPE_MAX_COUNT;
    }
    class ViewHolder {
        public ImageView imgBufLogo;
        public TextView txtBufResName;
        public TextView txtBufType;
        public TextView txtTime;
        public TextView txtBufDistance;
        public TextView txtReservePrice;
        public TextView txtOnlinePrice;
        public ImageView restRatingBar;
        public Button btnOnlinePrice;
        public Button btnReservedPrice;
        public TextView txtBufOffId;
        public TextView txtDate;
        public TextView txtBufDesc;
        MapView map;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final Map<String, CharSequence> objMap; 
        objMap = mListLayoutData.get(position);
        CharSequence value = "";
        String key = "";

        for (Entry<String, CharSequence> entry : objMap.entrySet()) {
            key = entry.getKey();
            value = entry.getValue();
        }

        final ViewHolder vHolder;

        int type = getItemViewType(position);
        if (convertView == null) {  

            vHolder = new ViewHolder();  
            String strStyleCont;

            switch (type) {
            case TYPE_OTHER_LAYOUT:
                convertView = mInflater.inflate(R.layout.buf_location_header, null); 
                vHolder.txtBufResName = (TextView) convertView.findViewById(R.id.txtBufRestName);
                vHolder.txtBufType = (TextView) convertView.findViewById(R.id.txtBufType);
                vHolder.txtTime = (TextView) convertView.findViewById(R.id.txtTime);
                vHolder.txtBufDistance = (TextView) convertView.findViewById(R.id.txtBufDistance);
                vHolder.restRatingBar = (ImageView) convertView.findViewById(R.id.restRatingBar);
                vHolder.imgBufLogo = (ImageView)convertView.findViewById(R.id.imgBufLogo);
                vHolder.txtBufOffId=(TextView) convertView.findViewById(R.id.txtBufOffId);
                vHolder.txtDate=(TextView) convertView.findViewById(R.id.txtDate);
                vHolder.txtBufDesc=(TextView) convertView.findViewById(R.id.txtBufDesc);
                vHolder.txtReservePrice=(TextView) convertView.findViewById(R.id.txtReservePrice);
                vHolder.txtOnlinePrice=(TextView) convertView.findViewById(R.id.txtOnlinePrice);
                vHolder.txtBufResName.setText(WordUtils.capitalize((String) objMap.get("res_name")));

                strStyleCont = WordUtils.capitalizeFully((String)objMap.get(buffets.COLUMN_BUF_TYPE_NAME), '/');
                vHolder.txtBufType.setText(strStyleCont);
                vHolder.txtDate.setText(CommonFunctions.ConvertSrcDateToSqLiteDateFormat((String) objMap.get(buffets.COLUMN_FROM_DATE))+" to "+ CommonFunctions.ConvertSrcDateToSqLiteDateFormat((String) objMap.get(buffets.COLUMN_TO_DATE)));
                vHolder.txtTime.setText(CommonFunctions.formatTime((String)objMap.get(buffets.COLUMN_FROM_TIME))+" to "+CommonFunctions.formatTime((String)objMap.get(buffets.COLUMN_TO_TIME)));
                vHolder.txtBufOffId.setText(objMap.get(buffets.COLUMN_BUF_OFF_ID));
                vHolder.txtBufDistance.setText(objMap.get(buffets.COLUMN_DISTANCE));
                vHolder.txtOnlinePrice.setText("Rs."+objMap.get(buffets.COLUMN_ONLINE_PRICE));
                vHolder.txtReservePrice.setText("Rs."+objMap.get(buffets.COLUMN_RESERVED_PRICE));
                vHolder.restRatingBar.setImageResource(CommonFunctions.setRating(objMap.get(buffets.COLUMN_RATING).toString()));
                Picasso.with(mContext).load(mContext.getString(R.string.URL_BUFFET_IMAGE).trim()+((String) objMap.get(buffets.COLUMN_BUF_IMAGE)).trim()).into(vHolder.imgBufLogo);
                vHolder.txtBufDesc.setText(objMap.get(buffets.COLUMN_BUF_DESC));


                //Launching the Image in the dialog onClick of the buffet logo
                vHolder.imgBufLogo.findViewById(R.id.imgBufLogo).setOnClickListener(new Button.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        DlgPhotoSelect.showQuitAlert(mContext, vHolder.imgBufLogo.getDrawable());
                    }
                });

                break;
            case TYPE_ITEM:

                int actionBarHeight = 0;
                int height = 0;
                convertView = mInflater.inflate(R.layout.buf_detail_location_itm, null);    
                //Find the map widget
                vHolder.map = (MapView) convertView.findViewById(R.id.map); 
                //Find the height of the screen 
                DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
                height = metrics.heightPixels;
                // Calculate ActionBar height
                TypedValue tv = new TypedValue();
                if (mContext.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
                {
                    actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,mContext.getResources().getDisplayMetrics());
                }
                //Set the final height of map widget(width=matchParent and the height(calculatedScreenheight-(actionbarheight*2))
                vHolder.map.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height-(actionBarHeight*2)));


                annotation = new AnnotationView(vHolder.map);
                //vHolder.map.getController().setZoom(14);
                //vHolder.map.getController().setCenter(new GeoPoint(Double.valueOf(latitude),Double.valueOf(longitude)));
                vHolder.map.setBuiltInZoomControls(true);


                vHolder.map.getController().setZoom(8);

                vHolder.map.setBuiltInZoomControls(true);

                vHolder.map.getController().setCenter(new GeoPoint(Double.valueOf((String) objMap.get(buffets.COLUMN_LATITUDE)),Double.valueOf((String) objMap.get(buffets.COLUMN_LONGITUDE))));
                //map.getController().setCenter(new GeoPoint(Double.valueOf(AppController.userLocdetails.get("userLatitude")),Double.valueOf(AppController.userLocdetails.get("userLongitude"))));


                // initialize the annotation to be shown later 
                annotation = new AnnotationView(vHolder.map);

                setLocMapMarker(vHolder.map,objMap);


                break;
            }
            convertView.setTag(vHolder);  
        } else {  
            vHolder = (ViewHolder) convertView.getTag();  
        } 
        return convertView;
    }

    private void setLocMapMarker(MapView map, Map<String, CharSequence> objMap) {

        // use a custom POI marker by referencing the bitmap file directly,
        // using the filename as the resource ID 
        Drawable icon = mContext.getResources().getDrawable(R.drawable.distance_icon_two_large);
        final DefaultItemizedOverlay poiOverlay = new DefaultItemizedOverlay(icon);


        OverlayItem poi1 = new OverlayItem(new GeoPoint (Double.valueOf((String) objMap.get(buffets.COLUMN_LATITUDE)),Double.valueOf((String) objMap.get(buffets.COLUMN_LONGITUDE))), String.valueOf(objMap.get(buffets.COLUMN_AREA_NAME)), String.valueOf(objMap.get(buffets.COLUMN_CITY_NAME)));
        poiOverlay.addItem(poi1);
        OverlayItem poi2 = new OverlayItem(new GeoPoint (Double.valueOf(AppController.userLocdetails.get("userLatitude")),Double.valueOf(AppController.userLocdetails.get("userLongitude"))), AppController.userLocdetails.get("userArea"), AppController.userLocdetails.get("userCity"));
        poiOverlay.addItem(poi2);
/////////
         // add a tap listener for the POI overlay 
          poiOverlay.setTapListener(new ItemizedOverlay.OverlayTapListener() {
          @Override
            public void onTap(GeoPoint pt, MapView mapView) {
               // when tapped, show the annotation for the overlayItem 
               int lastTouchedIndex = poiOverlay.getLastFocusedIndex();
               if(lastTouchedIndex>-1){
                   OverlayItem tapped = poiOverlay.getItem(lastTouchedIndex);
                   annotation.showAnnotationView(tapped);
               }
             }
          });

          map.getOverlays().add(poiOverlay);
        }   
}

如何解决此问题

1 个答案:

答案 0 :(得分:0)

您错过了ACTION_CANCEL。如果发生ACTION_CANCEL,则表示父视图已决定采取所有触摸,并且在所有手指都启动之后您不再接收。一般来说,将ACTION_CANCEL视为所有手指都可以起作用。

ListViews在滚动并窃取所有触摸事件时发送ACTION_CANCEL。其他可滚动视图也可能也是如此。