I want to create an interface for my android project. I have 4 seperate projects which will be used as libraries for the final project, 3 of which contain webviews. On the startup screen I want to have 4 buttons and then maybe use the onClick function to launch the respective app. I am having problems declaring the webview in my xml though. The libraries when imported contain webviews so where should they go in the xml? Also is there a way to start the activity of the project when the button is clicked? Instead of just calling methods from the project?
Thanks
What I do in this case is to extend the Service/Activity class from the other project in the project where I want to use it and then add it to the manifest.
For the layout files I was not able to use them directly in another project. So you could add an abstract Method to your webview activitys like
protected int getLayoutId()
and then copy your XML layout files to the core project where you reference the layouts using that method. Don't know if there is any better way to solve this I wasnt able to find any other solution.
Related
Currently, I am developing an android library. Basically the idea is to add some functionality to any android widget that there is. The library is used to create compound views, and the user should be able to convert every existing android widget/view into a compound view with some additional functionality I want to add dynamically.
Every one of these views should still be useable inside XML files, which means I cannot change the constructor too much.
Another requirement is that I need an option for the user to provide some classes for the views. By that, I mean that the created compound view is going to have a public variable named viewStore. Thy type of viewStore would either be the user's implementation of the ViewStore interface (preferred way but I am pretty sure this would require code generation as discussed later) or would be provided via generics.
In the end, a compound view would have this folder structure like this:
MyView Folder
MyView extends CoolViewWithViewStore extends AndroidWidgetChoosenByUser
MyViewStore implements ViewStore <- used in CoolViewWithViewStore
One option is to extend every single widget. I don't think I need to explain why this is a bad idea. Furthermore the user couldn't provide the additional classes that are needed.
Another one I thought of was Annotation with code generation. The problem I came across here was that the user needs access to variables of CoolViewWithViewStore inside MyView which wouldn't be possible because CoolViewWithViewStore would be generated at compile-time and furthermore the user could accidentally use his class inside XML instead of our generated one.
I would like to hear if anybody has a better idea of how to handle this or if there even is a clean solution to this to achieve this kind of architecture. If anybody has a better idea of how to structure my library I would like to hear this as well.
Using Kotlin extension function you could extend a class with new functionality without having to inherit from the class.
I am learning Android Studio and I have recently come across listview.
I am making a project which has 6 buttons and each of those 6 buttons will open an activity where there are 2 additional buttons and if you click on 1 of those 2 activities you will reach the required page.The required pages have different text content.
I am approaching this problem by creating a new xml file for every activity however this leads to creation of many pages and I just wanted to know if there is any method which will reduce the number of files created for this project
If your two activity have similar look than you can use same layout,
else you have to create different layouts for all your activity.
If you have Activities that looks alike you can use the same layout file for both activities, and only change the behavior in the Java side.
And if you have activities thats acts alike you can also use the same activity and change the behavior depending on some extras.
Can anyone have sample about quickreturnview gridview ? I used https://github.com/LarsWerkman/QuickReturnListView. but I have a bug when scrolling in gridview. Can you help me ?
I suggest you use alternative library (alike the one from your question) i.e. this one: https://github.com/allminewuwei/QuickReturnView
What you need to do is:
1. Download the library and import it in your workspace (I'm using eclipse terms, to the analog action in Android Studio)
2. Copy paste the two classes (shown in the screenshot) from the library project in to your project.
It would be neat if you open a separate package (smt like: com.yourapp.quickretrun)
resolve the issues (quick fix tips should do the trick)
Rename the QuickReturnListView class that you've imported in you project into QuickReturnGridView (or anything that will imply the nature of the widget) and do this change:
public class QuickReturnGridView extends GridView {
/*can extend any class that is extended from
don't change anything else within the class */
}
Lastly in the layout that you're going to make use of the newly created component, make sure that you follow this hierarchy (must have the exact layout_width and layout_height values) :
I have a fairly simple Android UI element that I created locally inside of a application project. This element is a EditText/Label combination that displays the hint text in the EditText but when the user starts to type in the field it floats the hint text as a label above the field.
I would like to be able to use this component in other projects. I've been unable to find any useful information about how to package separately from application so that I can reuse it in other places.
Thanks.
You need to create a library project. You can add to a library any classes that you want, including User Interface elements.
On your projects, you just add a reference to you library project to reuse it.
Check this link.
I'm using this library project in my Android application. But I need to make some customization for it.
For example, if I need a EditText instead of the provided TextView, what is the best practice to customize the library for my needs without writing code in the Project Library?
I made this customization by defining in the library's actionbar.xml layout a EditText instead of TextView, but I don't like this approach.
Do you have any guidelines, tutorials that could help me out?
In your special case I would suggest to use original compatibility's-package actionBar.
But to answer your question: you could always extend classes from the Library, which I think is the best practice if the library should kept untouched. Overriding Methods which you want to change their behavior keeps anything clean. You do the exact same every time you extend android-sdk classes, which you cannot change like you want.
In the case of changing layouts I'm not quite shure. I think I can remember that if the lib has an actionbar.xml and you have an actionbar.xml inside your project, too, yours will win. just like an "overriding layouts" feature