我想通过长按使布局可见,而再次单击则不可见,这对我不起作用。 请帮我解决一下这个。 代码如下。 当我单击一次布局可见后,再次单击该布局时,就不需要了,但仍然可见。
public class ReminderstestExplaination extends Fragment {
RecyclerView testexplntion_recycle;
CustomRecyclerview customRecyclerview;
LinearLayout reminderpage_addbutton,extraremlay,del_editlay;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.remindertest_explaination,container,false);
extraremlay = v.findViewById (R.id.extraremlay);
extraremlay.setOnLongClickListener (new View.OnLongClickListener () {
@Override
public boolean onLongClick(View view) {
del_editlay.setVisibility (View.VISIBLE);
return true;
}
});
}
答案 0 :(得分:0)
执行此操作,使用布尔变量跟踪可见性,并在每次长按时更改它。
public class ReminderstestExplaination extends Fragment {
boolean isVisible = false;
RecyclerView testexplntion_recycle;
CustomRecyclerview customRecyclerview;
LinearLayout reminderpage_addbutton,extraremlay,del_editlay;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.remindertest_explaination,container,false);
extraremlay = v.findViewById (R.id.extraremlay);
extraremlay.setOnLongClickListener (new View.OnLongClickListener () {
@Override
public boolean onLongClick(View view) {
if(isVisible) {
isVisible = false;
del_editlay.setVisibility
(View.INVISIBLE);
}
}
else {
isVisible = true;
del_editlay.setVisibility
(View.VISIBLE);}
return true;
}
});
}