Android Layout: Is reusable component UI possible? - android

I'll preface this with, I've just started learning Android so be gentle.
I come from an ASP.NET / Silverlight background so I was looking for something along the lines of controls.
I want to reuse a layout (a ListView item template) in other layouts.
Such that in my other layouts I can just add <myListItem /> to show it.
Is this, or anything like it possible? or are there better ways?

This is very possible; you just need to use the <include /> tag. Basically, you put your layout in a file, then you do:
<include layout="#layout/my_list_item_template" />
Romain Guy goes into detail on how to use it here: http://www.curious-creature.org/2009/02/25/android-layout-trick-2-include-to-reuse/
(Android documentation)
(I am assuming that what you want is a reusable layout, not a custom component. The difference being, a reusable layout is like reusing snippets of standard components, whereas a custom component is used when you need to extend the functionality of a particular widget, like a TextView or Button. If you want a custom component, then you'll have to do a lot more legwork to Erich Douglass' answer for more on that.)

Related

Is it possible to add custom interactive UI elements to EditText?

A bit of context here. I'm an iOS developer with no knowledge on Android development.
I need to know whether it's feasible in Android to embed custom interactive UI elements (in iOS that'd be a UIView) inside of EditText.
A library I found to do this in iOS is: https://github.com/vlas-voloshin/SubviewAttachingTextView
You can see a GIF in that link showcasing the kind of behavior I'm looking for.
Is there built in support, or any third party library I can use to achieve something similar in Android?
in normal way this is not possible in android and we don't have any standard component or any library (that i know) for doing such a thing but we can create something similar to this (for this you should search about custom Views in android !) and also there is other way and easier way to achieve something similar to this is using the container layouts in android like LinearLayout and adding all your component to that container layout in run-time base on your text ! for example in your code you can dive in to your text and find tags like or and create appropriate view for your tag and add it to your container layout and at the end your layout looks like that gif wich is in your question ! and also in android we can show some basic html code in textView

Dynamic UI Controls in Android

I am in a situation like i have to generate UI Controls like Button,Switcher,Progress Bar, Label text etc based on my list Items .
I am looking for a way to generate the controls in a View and add Views with generated controls in a Layout .
Can anyone give me a proper way to do that?
Why not to use Fragments?
Google docs about this here
and little tutorial here
You may want to take a look at the Metawidget source code. The Android version of Metawidget makes extensive use of generating Views and Layouts at runtime (e.g. see org.metawidget.android.widget.widgetbuilder.AndroidWidgetBuilder). You may even find Metawidget itself will suit your needs (it's designed to be embedded into projects for use-cases such as this).

Toolbar below ListView

I am working on an application that involves me having to place a toolbar at the bottom of each activity. The toolbar will have 4 buttons on it, each starting new activities.
I am just wondering, and I apologize for how general the question, is there a proper way to go about implementing this? my plan was to but a linear layout element in each xml layout file with horizontal orientation. Then four button elements inside of that...
It seems like a huge amount of work considering I will have a lot of activities..
What you want sounds a lot like Android's ActionBar. Check this link for a guide to its usage. If you use this, your app will look and feel more consistent with the operating system, as so many apps now use the ActionBar (which is a lot of them), and you gain a lot of power for what you want to show there, and how you want to do it.
ActionBar was only introduced in Android version 3 (Honeycomb), but there's a compatibility library, ActionBarSherlock which allows you to use it in older versions of Android as well.
Hope it works for you!
You can use a same xml for various views. So I suggest creating a generic xml, then using Inflaters and other resources as strings, xmls etc. to prepare the generic xml whenever any Activity is loaded. So you can reuse it the xml.

Iphone equivalent to Android <include> and <merge> tag?

I'm going to port an Android application over to the iPhone platform. I need header-footer like functionality so I'm looking for Android-style layouts merging for iPhone.
Does iPhone support this? If so, how?
[EDIT]
May be above header-footer description creating confusion.I am trying to describe again.
I would like to merge two different .xib file's view in single xib.for an example I have "footer.xib",I just want to include (reuse) same "footer.xib" view in different pages instead of copying same code for each page. I'm very new to Iphone world, so any guidance would be appreciated!
I'd second the notion of going from scratch. I'd question why you'd need header functionality (UINavigationController provides a default header), but with the footer, do this:
Create a subclass of a UIView or UIToolbar or the like, and do custom drawing or custom layout in code. Then, place them in your views by dragging a UIView into a NIB/.XIB view controller file and changing the "Custom Class" field to that of your subclass, or programmatically add them.

Tips on making custom, reuesable components in Android

I want to create a component that will appear as a navigation menu for an Android application. Basically, the custom component is a rectangular "Div" (to use HTML terms) that contains six buttons. Each button provides a link to another part of the application. I want to use this on every "page", so I want to make it easy to maintain.
What is the recommended class to extend for creating custom components like this? (I've seen the "Widget" class, but not sure If this should only be used for widget that appear outside the app (like Google search))
And
Is the process as simple as creating the custom "Widget" class with it's own XML layout and then adding it to each Activity class?
The class to extend is View, the Widget class is for widgets in the homescreen. This is a nice doc to read: Building Custom Components, I suggest to look at the Compound Controls section, that seems suitable for your problem.
Is the process as simple as creating the custom "Widget" class with it's own XML layout and then adding it to each Activity class?
Yes, once you have written your own view, you just have to add it to your layouts in the XML (just like you do with the android views), something like this:
<com.your.package.YourNiceView
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>

Categories

Resources