gpt4 book ai didi

java - 是否可以在 Java 中实现私有(private)接口(interface)或扩展私有(private)类?

转载 作者:太空狗 更新时间:2023-10-29 14:55:00 24 4
gpt4 key购买 nike

我与 android EditText 斗争了好几天,尝试摆脱选择文本时的“粘贴”弹出窗口。 (我的扩展 EditText 是只读的和可选择的)。

从答案到问题:EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event

覆盖package-private 方法 canPaste() 对于dalvik runtime 是可以的,但是不能在使用ART 的android 5.0 上面工作。

所以我找到了其他方法来解决问题,不是覆盖方法,而是尝试替换编辑器的字段变量

我看 EditText 的帮助类 Editor 有很多特定的逻辑,看看我是否可以在适当的时候替换 InsertionPointCursorController一个虚拟子类,它不会显示弹出窗口。 (InsertionPointCursorController 是一个私有(private)类,它实现了一个私有(private)接口(interface),所以要用一个虚拟子类替换它,我需要扩展类或实现接口(interface))

public boolean performLongClick(boolean handled) {
// Long press in empty space moves cursor and shows the Paste affordance if available.
if (!handled && !isPositionOnText(mLastDownPositionX, mLastDownPositionY) &&
mInsertionControllerEnabled) {
final int offset = mTextView.getOffsetForPosition(mLastDownPositionX,
mLastDownPositionY);
stopSelectionActionMode();
Selection.setSelection((Spannable) mTextView.getText(), offset);
getInsertionController().showWithActionPopup();
handled = true;
}

看起来 getInsertionController().showWithActionPopup(); 显示弹出窗口 :(

现在我将尝试使用 replace remove callback 作为替代方案

最佳答案

你不能扩展外部私有(private)类(在同一个包中默认,在其他包中保护可以)和接口(interface)。

扩展您的父类,您需要更改并重写您需要使用的方法,但同样您不能重写私有(private)方法。您可以重新编码它们(非常“重载”)。

关于java - 是否可以在 Java 中实现私有(private)接口(interface)或扩展私有(private)类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32370012/

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