Swipe to Delete Not working from the Top item of the listvie



我正在使用this作为滑动删除。但是我在仅实现列表的删除菜单项时遇到问题。

我所做的只是创建一个单独的删除项。我真的不想使用任何其他项目,如演示中显示的Open。

这是我的设计

   <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#dadada">

    <RelativeLayout                 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/segmented_buttons">
        <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/swipe_refresh_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clickable="false"
                android:orientation="vertical">

                <!--<ScrollView-->
                <!--android:layout_width="match_parent"-->
                <!--android:layout_height="match_parent"-->
                <!--android:layout_gravity="center"-->
                <!--android:gravity="center"-->
                <!--android:clickable="false">-->
                <TextView
                    android:id="@+id/swipeRefreshLayout_emptyView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center|center_vertical"
                    android:enabled="false"
                    android:gravity="center"
                    android:visibility="gone" />

                <com.baoyz.swipemenulistview.SwipeMenuListView
                    android:id="@+id/listView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:clickable="true"
                    android:clipChildren="false"
                    android:divider="@android:color/transparent"
                    android:dividerHeight="5.0sp" />
                <!--</ScrollView>-->
            </FrameLayout>

        </android.support.v4.widget.SwipeRefreshLayout>
    </RelativeLayout>

</RelativeLayout>

这是我如何在Fragment 中创建菜单

SwipeMenuCreator creator = new SwipeMenuCreator() {
        @Override
        public void create(SwipeMenu menu) {
              // create "delete" item
            SwipeMenuItem deleteItem = new SwipeMenuItem(
                    getActivity());
            // set item background
            deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9,
                    0x3F, 0x25)));
            // set item width
            deleteItem.setWidth(dp2px(90));
            // set a icon
            deleteItem.setIcon(R.drawable.ic_delete);
            // add to menu
            menu.addMenuItem(deleteItem);
        }
    };

以下是我如何设置创建者

// set creator
    mListView.setMenuCreator(creator);

我的问题如前所述,我有几个关于删除的问题

  1. 当我的列表中有太多数据时,比如说行数是10并且需要向下滚动时,删除选项甚至从列表视图的第一行起就像一个魅力
  2. 当列表中有较少的项目时,或者如果我继续从底部删除项目,我指的是最后一行,当不需要向下滚动、无法顺利删除的项目较少时,需要多次刷新列表,或者从右到左再次打开和关闭菜单,在删除菜单上进行多次向下触摸,然后在多次尝试后删除一些内容
  3. 我不知道背后的问题是什么,但当我制作了两个菜单,如演示中所示的打开和删除时,我将打开和删除都作为删除按钮,所以在情况0和情况1中,我编写了删除代码,然后我注意到每次触摸打开时删除都在工作,但当我再次点击删除时,有时会删除项目,有时会多次尝试

可能有什么问题?你猜得到了吗?周围有工作吗?

当然,当我触摸删除菜单时,它会给我一个日志,向下看,它会在日志中显示这一点,当我点击删除时,它实际上不起作用,但当它开始工作时,日志中的这条消息永远不会出现。

D/ViewRootImpl:ViewPostImeInputStage ACTION_DOWN

编辑一个

这是我的适配器的全部代码:

    public class SwipeListOfferAdapter extends BaseAdapter {
    private Activity activity;
    private LayoutInflater inflater;
    private ArrayList<OfferStatusData> offerList;
    OfferStatusData offerStatusData;

    public SwipeListOfferAdapter(Activity activity, List<OfferStatusData> offerList) {
        this.activity = activity;
        this.offerList = (ArrayList)offerList;
        inflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        // bgColors = activity.getApplicationContext().getResources().getStringArray(R.array.movie_serial_bg);
    }
    @Override
    public int getCount() {
        return offerList.size();
    }
    @Override
    public Object getItem(int location) {
        return offerList.get(location);
    }
    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder ;

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.row_offer_status, null);
            holder = new ViewHolder();
         //   holder.tvCustomerName = (TextView) convertView.findViewById(R.id.tv_row_customer_name);
            holder.tvOfferName = (TextView) convertView.findViewById(R.id.row_offer_name);
           // holder.tvEmail = (TextView) convertView.findViewById(R.id.row_email);
            holder.tvPhoneNumber = (TextView) convertView.findViewById(R.id.row_phone_number);
            holder.tvAddress = (TextView) convertView.findViewById(R.id.row_address);
            holder.tvTmcBrand = (TextView) convertView.findViewById(R.id.row_tmc_brand);
            holder.tvStartEndTime = (TextView) convertView.findViewById(R.id.row_offer_time);
            holder.tvNoOfPerson = (TextView) convertView.findViewById(R.id.tv_row_total_person);
            holder.tvNoOfAcceptors = (TextView) convertView.findViewById(R.id.tv_row_total_acceptors);
            holder.tvMonth = (TextView) convertView.findViewById(R.id.tv_row_month);
            holder.tvDay = (TextView) convertView.findViewById(R.id.tv_row_day);
           // holder.tvCustomerName = (TextView) convertView.findViewById(R.id.tv_row_customer_name);
            convertView.setTag(holder);
        }
        else {
            holder = (ViewHolder) convertView.getTag();
        }
        if(offerList.size()>0){
            offerStatusData = (OfferStatusData)offerList.get(position);
           // holder.tvCustomerName.setText(offerStatusData.getName());
            holder.tvOfferName.setText(offerStatusData.getOffer_name());
           // holder.tvEmail.setText(offerStatusData.getEmail());
            holder.tvPhoneNumber.setText(offerStatusData.getPhone_number());
            holder.tvAddress.setText(offerStatusData.getAddress());
            holder.tvTmcBrand.setText(offerStatusData.getTmc_brand());
            holder.tvStartEndTime.setText(offerStatusData.getStart_time()+"-"+offerStatusData.getEnd_time());
            holder.tvNoOfPerson.setText(offerStatusData.getNo_of_person());
            holder.tvNoOfPerson.setTextColor(Color.parseColor("#F66D0D"));
            holder.tvNoOfAcceptors.setText(offerStatusData.getCurrent_acceptors()+"/"+offerStatusData.getNo_of_person());
            holder.tvNoOfAcceptors.setTextColor(Color.parseColor("#2B5BD2"));
// holder.tvMonth.setText("july");
//                holder.tvDay.setText("29");
            String dateFromService = offerStatusData.getDate();
            String[] monthFromService = dateFromService.split("-");
            Log.d("date split", dateFromService.toString());
            holder.tvDay.setText(monthFromService[2].toString());
            holder.tvDay.setTextColor(Color.parseColor("#57902B"));
            holder.tvMonth.setText(getMonth(Integer.parseInt(monthFromService[1])));
            holder.tvMonth.setTextColor(Color.parseColor("#57902B"));
        }

        return convertView;

//        String color = bgColors[position % bgColors.length];
//        serial.setBackgroundColor(Color.parseColor(color));

    }
    void  delete (int post){

        offerList.remove(post);
    }
    class ViewHolder{
        TextView tvOfferName,tvPhoneNumber,tvAddress,
                tvTmcBrand,tvStartEndTime,tvNoOfPerson,tvNoOfAcceptors,tvMonth,tvDay;
    }
    public String getMonth(int month) {
        return  new DateFormatSymbols().getShortMonths()[month-1];
        // return new DateFormatSymbols().getMonths()[month-1];
    }
}

所以我真的不知道这背后的主要原因是什么,没有任何线索留给我。请告诉我可能是什么问题。

试试这个,

listView.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                // Disallow View pager to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(true);
                break;
            case MotionEvent.ACTION_UP:
                // Allow View pager to intercept touch events.
                // v.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }
            // Handle Listview touch events.
            v.onTouchEvent(event);
            return true;
        }
    });

最新更新