MainActivity extends Application {
...
}
What is the use of writing extends Application?
Extends means that it inherits from Application, therefore having all of the Application properties, methods, and so forth, but extends it with your specific functionality. In other words, MainActivity adds more to the base Application.
Related
I'm a little bit confused with how GetView works. I currently have a page that needs to have at least 2 different controllers. From what I've seen, people mostly use GetView as opposed to Get.find() for better code format, however GetView seems to only use 1 controller, for example:
class HomeScreen extends GetView<HomeController>
I have tried to google it and haven't found any solution. I also have tried to use
class HomeScreen extends GetView<HomeController> with GetView<UserController>
But it gave me an error that says
The class 'GetView' can't be used as a mixin because it extends a class other than 'Object'.
I would very appreciate if you can give me a solution or a workaround to use GetView with two or more controllers.
Please note that I'm using GetX bindings (therefore I have already wrote Get.put(Controller()) in another file) and I want to avoid using Get.find in my widget tree.
Can you please explain what's the usecase of using GetView with multiple controllers? It's not supported. Because a view can have multiple controllers but how many?
Therefore, in that case, you should just use the GetX widget for different controllers like:
GetX<Controller1>(),
GetX<Controller2>(),
and so on
Need your assistance. I created 2 custom ClassLoaders to load class files. But when I try to use .getClassLoader() on class I loaded, I saw ApplicationClassloader every time.
ClassLoader in Java works on three principle:
delegation,
visibility
uniqueness
Delegation principle forward request of class loading to parent class loader and only loads the class, if parent is not able to find or load class. Visibility principle allows child class loader to see all the classes loaded by parent ClassLoader, but parent class loader can not see classes loaded by child. Uniqueness principle allows to load a class exactly once, which is basically achieved by delegation and ensures that child ClassLoader doesn't reload the class already loaded by parent.
The class you are trying load should be there in your class path. Please check your application classpath
Read more: here
It means that your class is indeed defined by the application class loader, not your custom one. Your custom class loader is just initiating class loader that delegates to its parent (application class loader). Make sure the custom class loader defines the class itself.
I have a program which shows lists of files in directories on the SDCARD and when the user clicks on a file it opens the PDF up. For instance one activity will display the contents of one folder.
I have been wanting to add the ActionBar for navigation and can get the ActionBar to work in its own activity and my ListActivity to work in its own activity, however I cannot get them to work together.
I am not sure how to combine the two so that I end up with one activity that displays the action bar and the file list in the one Activity?
The Actionbar Activity starts with
public class SecondActivity extends FragmentActivity implements ActionBar.OnNavigationListener {
The Activity that displays the clickable list starts with
public class MainActivity extends ListActivity {
My android app programming is quite basic and self taught so I am probably missing something obvious. Thanks in advance
I have posted an alternative solution that separates the concerns of the List and the ActionBar. Makes the code a little tidier IMO.
I think you can extend your class to ListActivity and override method onCreateOptionsMenu to bind your action bar to the activity:
public class MainActivity extends ListActivity {
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.your_action_bar_name_here, menu);
return (super.onCreateOptionsMenu(menu));
}
// your other methods
}
I have an Android app that has an Application class and I have another class that extends PhoneStateListener.
I would like to use one of the objects from the Application class in my class that extends the PhoneStateListener. I wasn't able to do so because it the PhoneStateListener class doesn't extend Activity.
Is there any way I can use the object from the Application class within my PhoneStateListener class?
See this example and this Question
Extend PhoneStateListener and have a constructor that takes what it wants as argument.
Thats a general question about: How to structure my website with all its pages and components (here panels) in wicket. I would like to show my attempt and hope someone can give me advice, wheather its a good way or if there is a better one.
My Structure is like:
Root: HomePage
Page1 extends HomePage
Page2 extends HomePage
Page3 extends HomePage
The pages wrap the content and its own navigation. They get init in HomePage.html with wicket child.
Now, when I define a new Panel for Page1, I have to define a link for it as well. For the link onClick() I set the panel to which it refers to visible and all other panels to invisible. Also I have to define on the Page1 the panel, which gets shown when I navigate to Page1. All other panels are invisible.
Is this a good attempt or is there a better way? Now I initialize ever panel and just hold them invisible.
A shot at answering your questions... This assumes you're using Wicket 1.4.x.
First, you can have many levels of Page classes, often mimicking the overlap of the design and function. For example, say you have an application where people "Write", "Browse" and "Read" user-created books.
RootPage - common headers/footers, javascript imports
AbstractWritePage extends RootPage - for anything regarding authoring
AbstractBrowsePage extends RootPage - browsing
AbstractReadPage extends ReadPage - reading
Then, I implement something like:
FullLibraryPage extends AbstractBrowsePage
FilterSearchPage extends AbstractBrowsePage
In the long run, it gets complicated, but very powerful.
Secondly, your Panel components that go visible/invisible. If you're using Wicket 1.4.x, you should look at the overrideable method onConfigure() for each Panel. In this panel, you can set the visibility like:
#Override
protected void onConfigure() {
super.onConfigure();
setVisible(!navTriggered);
}
where navTriggered is a boolean value residing in the containing page. Then, your link could do a simple:
#Override
protected void onClick(AjaxRequestTarget target) {
navTriggered = false;
target.addComponent(/* Appropriate panels; see below for multiples */);
}
The advantage to this is that you can have multiple panels triggered by the same boolean variable. There is nothing wrong with creating all of your panels at page creation time, even if they start out invisible.
Finally, if you have a lot of panels that need to be changed/triggered/etc, consider pairing an IVisitor with a marking interface. Something like...
public class Panel1 implements MyPanelGroup { ... }
public class Panel2 implements MyPanelGroup { ... }
Then, you can use an IVisitor to visit every instance of MyPanelGroup in a page and do something with visibility (either set visibility, add it to the AjaxRequestTarget, etc).
Hope that answers something :)