5
Problem
I’m trying to create some extra behaviors in some native Android components.
For that I am creating a class
above the Android component and rewriting some situations I intend to have a different behavior, and I came across a situation I need in my custom method, call a method of class
inherited (in this case the Android component), but the method is not accessible to my class
, since he is international and not protected
, and my class
is in another package
.
Questions?
- Although I know which attributes and methods
internal
are only accessible for members of the samepackage
Java, I wonder if there are any how to access these methods from aclass
of a anotherpackage
? - And optionally, if there is any other way to overwrite Android native components, who avoid this kind of problem?
Example of what I’m trying to do:
public class MeuAbsListView extends AdapterView<ListAdapter>{
public MeuAbsListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void meuMetodoDisparadoPeloMeuEvento(){
// faz seu comportamento custumizado ...
// e tem esse metodo 'rememberSyncState' do 'AdapterView' que preciso chamar
// só que ele é internal e não tenho acesso a ele,
// já no AbsListView nativo é possivel pois ele é do mesmo package do AdapterView
rememberSyncState();
}
}
In the code Android Adapterview source the method is declared as:
void rememberSyncState() {
// codigo do rememberSyncState ...
}
I didn’t understand: "Is there any other way to overwrite native Android components, who avoid this kind of problem?" You want to create a subclass that makes the visibility of a class method less restrictive than in the superclass?
– Math
@Math, it’s out there, I believe that’s not possible, since it goes against everything, but I wanted to remove the doubt.
– Fernando Leal
I spoke nonsense in my previous comment, you can not leave MORE restrictive, IE, if you have a method without modifier you can leave it less restrictive in a superscript of a subclass your.
– Math