从ArrayList中删除无法正常工作

时间:2015-12-03 21:17:48

标签: android

protected void onActivityResult(int requestCode, int resultCode, Intent data) {    
        final LinearLayout layout = (LinearLayout) findViewById(R.id.main);
        final TextView todo = new TextView(this);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT , 180);
        todo.setLayoutParams(params);

        todo.setOnTouchListener(new OnSwipeTouchListener(this, todo, layout) {
            @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
            public void onSwipeRight() {
                todo.animate().translationX(500).alpha(0f).setDuration(250).setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        layout.removeView(todo);
                        Log.i("REMOVE111111111111111", Boolean.toString(textList.remove(todo.getText().toString())));
                        Log.i("REMOVE22222222222222", Boolean.toString(todoList.remove(todo)));
                    }
                })
                .start();

            }
        });
        todoList.add(todo);
        Collections.sort(todoList, new todoComparator());
        textList.clear();
        for (TextView t: todoList) {
            textList.add(t.getText().toString());
        }
        int counter = 0;
        for (TextView t: todoList) {
            if (counter > 0) {
                ((ViewGroup) todo.getParent()).removeView(todo);
            }
            layout.addView(todo);
            counter++;
        }

当我向右滑动textview时,我希望它与textList和todoList中的相应数据一起被删除。我试着测试一下,发现在onAnimationEnd方法中我的textList.remove()和todoList.remove()似乎有时会返回false,我不确定为什么。有任何想法吗?谢谢。 对不起,因为不清楚。正在删除textview,但textList.remove()和todoList.remove()有时会返回false。

1 个答案:

答案 0 :(得分:0)

您应该将触摸屏设置为"布局"而不是" todo"