gpt4 book ai didi

java - 无法更新自定义适配器中的项目

转载 作者:行者123 更新时间:2023-11-29 19:12:34 25 4
gpt4 key购买 nike

我正在尝试为 ListView 中的每个项目添加 touchlistener。这是我在 CustomAdapter 中用于 currentView 的代码(如我所想)

rowView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
x1 = event.getX();
return true;
case MotionEvent.ACTION_UP:
x2 = event.getX();
float deltaX = x2 - x1;
if (Math.abs(deltaX) > MIN_DISTANCE) {
if (x2 > x1) {
LEFT = false;
Logger.e("FALSE ");
txtTitle.setText("LEFT TO RIGHT");
moveLefttoRight = new TranslateAnimation(0, -150, 0, 0);
moveLefttoRight.setDuration(1500);
moveLefttoRight.setFillAfter(true);
swipeLayout.setAnimation(moveLefttoRight);
HomeChatAdapter.super.notifyDataSetChanged();
}
else {
LEFT = true;
Logger.e("TRUE");
txtTitle.setText("RIGHT TO LEFT");
moveLefttoRight = new TranslateAnimation(0, -150, 0, 0);
moveLefttoRight.setDuration(1500);
moveLefttoRight.setFillAfter(true);
swipeLayout.setAnimation(moveLefttoRight);

}

} else {
CLICKITEM = true;
return false;
}
break;
}
return false;
}
});

动画和 view.setText("blabla") 的问题当我完成“从左到右或从右到左”的滑动时屏幕上没有变化如果我搬出去txtTitle.setText("从左到右");

                        moveLefttoRight = new TranslateAnimation(0, -150, 0, 0);
moveLefttoRight.setDuration(1500);
moveLefttoRight.setFillAfter(true);
swipeLayout.setAnimation(moveLefttoRight);

这部分代码来自 TouchListener - 一切正常,但它在创建时工作了一次。任何人都可以帮助我在这种情况下如何解决?只想将 ListView 中的项目向左或向右移动。关注彼得。

最佳答案

如果我没有正确理解你的问题,你想使用

swipeLayout.startAnimation(...);

相反。

根据 setAnimation vs startAnimation in android :

setAnimation

Sets the next animation to play for this view.But view animation does not start yet.

startAnimation

If you want the animation to play immediately, use startAnimation. This method provides allows fine-grained control over the start time and invalidation, but you must make sure that

1) the animation has a start time set,

2) the view will be invalidated when the animation is supposed to start.

关于java - 无法更新自定义适配器中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44780964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com