gpt4 book ai didi

java - setOnClickListener 和 setOnLongClickListener 不能同时工作

转载 作者:行者123 更新时间:2023-11-30 05:11:39 27 4
gpt4 key购买 nike

setOnClickListener 和 setOnLongClickListener 不能同时工作。当我删除一个时,另一个起作用,反之亦然。

另外我要说的是,如果把第一行代码改成childRelativeLayout.setVisibility(View.GONE);,那么parentRelativeLayout.setOnClickListener根本不起作用。

        childRelativeLayout.setVisibility(View.VISIBLE);
Animation slide_down = AnimationUtils.loadAnimation(context, R.anim.slide_down);
Animation slide_up = AnimationUtils.loadAnimation(context, R.anim.slide_up);

parentRelativeLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (childRelativeLayout.getVisibility() == View.GONE) {
childRelativeLayout.startAnimation(slide_down);
slide_down.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
childRelativeLayout.setVisibility(View.VISIBLE);
}

@Override
public void onAnimationEnd(Animation animation) {
}

@Override
public void onAnimationRepeat(Animation animation) {
}
});
} else {
childRelativeLayout.startAnimation(slide_up);
slide_up.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}

@Override
public void onAnimationEnd(Animation animation) {
childRelativeLayout.setVisibility(View.GONE);
}

@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
}
});

和onLongClick

        itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
AlertDialog.Builder mBuilder = new AlertDialog.Builder(context);
mBuilder.setTitle("Edytuj zadanie");

LayoutInflater mInflater = LayoutInflater.from(context);
@SuppressLint("InflateParams") View mView = mInflater.inflate(R.layout.daily_alertdialog, null, false);

//here is code...

mBuilder.setView(mView);
AlertDialog alertDialog = mBuilder.create();
alertDialog.show();

return true;
}
});

parentRelativeLayout

<RelativeLayout
android:id="@+id/parentRelativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8sp"
android:paddingStart="8sp"
android:paddingEnd="8sp"
android:paddingBottom="4sp">

<TextView
android:id="@+id/goal_list_name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="22sp"
android:layout_marginBottom="8sp"
android:textColor="@android:color/black"
android:textSize="18sp"
tools:text="Cel 1" />

<TextView
android:id="@+id/category_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/goal_list_name_text_view"
android:textColor="@android:color/darker_gray"
android:textSize="12sp"
tools:text="Kategoria: xyz" />

<TextView
android:id="@+id/place_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/goal_list_name_text_view"
android:layout_centerHorizontal="true"
android:textColor="@android:color/darker_gray"
android:textSize="12sp"
tools:text="Miejsce wykonania:" />

<TextView
android:id="@+id/date_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/goal_list_name_text_view"
android:layout_alignParentEnd="true"
android:textColor="@android:color/darker_gray"
android:textSize="12sp"
tools:text="14 luty 2018" />

<TextView
android:id="@+id/time_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/date_text_view"
android:layout_alignBottom="@+id/goal_list_name_text_view"
android:textColor="@android:color/darker_gray"
android:textSize="12sp"
tools:text="16:00" />

</RelativeLayout>

childRelativeLayout

 <RelativeLayout
android:id="@+id/childRelativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/parentRelativeLayout"
android:layout_margin="4sp"
android:animateLayoutChanges="true"
tools:ignore="Orientation"
android:visibility="gone">

<View
android:id="@+id/childView"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#f5000000"
android:layout_marginTop="2sp"/>

<TextView
android:id="@+id/plusDayTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12sp"
android:layout_marginTop="2sp"
android:clickable="true"
android:focusable="true"
android:text="@string/oneDay"
android:textColor="@android:color/black"
android:textSize="12sp" />

<TextView
android:id="@+id/doneTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="2sp"
android:layout_marginEnd="12sp"
android:clickable="true"
android:focusable="true"
android:text="@string/done"
android:textColor="@android:color/black"
android:textSize="12sp"
tools:ignore="RelativeOverlap" />

</RelativeLayout>

slide_down.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" >

<translate
android:duration="400"
android:fromYDelta="-60%"
android:toYDelta="0" />

slide_up.xml

<translate
android:duration="400"
android:fromYDelta="0"
android:toYDelta="-60%" />

最佳答案

您的 onLongClick 正在返回 true 向操作系统指示该事件已被处理并且不应调用其他点击事件。尝试将该值更改为 false,应该可以解决您的问题。

关于java - setOnClickListener 和 setOnLongClickListener 不能同时工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53624050/

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