execute class from included layout - java

Within my layout I have set a Include Other Layout. this layout schould in his turn show a listview with items loaded from the web (my webserver)
the only problem is: the items don't load in because the class that holds the code to load the items isnt called on because im using a Include Other Layout meaning only the layout is called and not the functional code from any .java files (classes)
leaving me with a blank page...
is there a way to make a call upon the class containing the code for the layout i have included?

<include/> tag is only for including only the view into another layout. It can be very useful if you use a common view everywhere. A ProgressBar can be an example. You can include ProgressBar everywhere you want. But it is just a UI.
If you also want the functionality you should use Fragments. Actually Fragments are exactly for what you describe.
Here is the tutorial from Android Developers official website
http://developer.android.com/training/basics/fragments/index.html

Related

Android app: 2 problems with layout

After ionic and angular i'm trying to develop apps in native java. After setting up a toolbar and a drawer-menu i wasn't able to make it work:
First problem: How can i use myitems in my drawer to show different views (in separate .xml files) in the main view.
Second problem: How can i create a view, similar to a full-height snackbar, whitin a text input field?
thank you for your time.
You should use fragment replacement. So in your main activity layout file create Frame Layout and onNavigationDrawerClick change fragments. Take a look at this as example.
2.I recommend you to use Bottom Sheet in it. Sample
If you need some code recommendations comment here. Good luck

Fragment Z-order changes when orientation changes

My main xml file has a FrameLayout, with one fragment defined in the XML. At runtime, I am adding another fragment on top of this, and then a third fragment on top of this. When I add the runtime fragments, I don't give containerIds to attach them to. This is all fine until the orientation changes. After the orientation change, the third fragment has gone beneath the second fragment. But obviously I want the z-order to stay how it was before the orientation change, i.e. the last fragment added should be on top and visible.
I've tried using containerIds when adding the fragments, and adding them to the FrameLayout defined in XML, but when I put in containerIds, the runtime fragments simply don't show up at all.
So I'm wondering why the fragments added at runtime don't show when I use a containerId. Is it because they are being added to a container which already contains a fragment (the one defined in XML)? How can I get around this? I've tried adding additional containers to the XML to hold the runtime fragments, but this doesn't seem to work. The only way to get the fragments to show is to remove the containerId from the call to FragmentTransaction.add().
Also, is it possible to change the z-order of fragments manually? I've searched Google quite a lot to find this out and haven't found any answers. I've tried using ViewGroup.bringChildToFront() and using the view returned by the fragment's getView() but this hasn't worked. I've also found out that you can nest fragments on Android 4.2+ with getChildFragmentManager(), but I'm supporting older APIs, and this method doesn't seem to be in the support library.
Any help greatly appreciated!
The way I got around this was to manually recreate the third fragment after the orientation change, and remove the one created by the system.

Scrollable PagerTabStrip

I've been searching for this topic for a while, and can't find enough resources or tuts about scrolling a PagerTabStrip. I'm using the FragmentStatePagerAdapter and populates the PagerTabStrip with getPageTitle(int position). I'd like to know how to make the titles scrollable. I'd like to scroll the titles without affecting the view by the time I stop or select into a specific title, then that's the time the view gets updated. I've been thinking to use HorizontialListView but not sure how to start. Hoping to learn from you. Thanks.
Found this on docu:
PagerTabStrip is an interactive indicator of the current, next, and
previous pages of a ViewPager. It is intended to be used as a child
view of a ViewPager widget in your XML layout. Add it as a child of a
ViewPager in your layout file and set its android:layout_gravity to
TOP or BOTTOM to pin it to the top or bottom of the ViewPager. The
title from each page is supplied by the method getPageTitle(int) in
the adapter supplied to the ViewPager.
I been searching on this on the web, but I didn't get any relevant resources. I just found out another library called actionsherlock that enables the scrolling of tabs without affecting the view which is exactly what I need, instead of using PagerTabStrip's listener .
I'm also searching for the same thing. Too bad you have to make your own implementation or use third-party library. I have read that this library offer the feature of scrolling tab independent of the content. But I have not tried it out yet.
http://viewpagerindicator.com/?utm_source=androidweekly&utm_medium=toolbox
Do you actually mean the ActionBarSherlock? Do you have an example?

How to compose the Android Equivalent of a custom JPanel (AKA View)

I am trying to create a really involved UI for integrating with a proprietary product (it's currently web based and a total hack). Each screen/view has the same look-and-feel, the same 2-3 buttons in the same locations on every page. It's just 1 portion of that display changes.
If this were swing I would define a JPanel, compose everything but this center component, and then create instances of said panel Supplying the differing fields per instance.
I want to represent the 90% common portions of this UI flow as a single view and just fill in some blanks.
Can I do that? How do I do that? No haters please. Total Android rookie (seasoned Java vet though)
Can I do that?
Sure! However, I wouldn't describe it as a "total Android rookie" sort of problem, just as it wouldn't be a "total Swing rookie" sort of problem in that environment.
How do I do that?
There are a few possible approaches. The simplest solution is to define a layout resource file that defines the entire UI, with a FrameLayout as the placeholder where "some blanks" will eventually go. Then, at runtime, when you use that layout, you would "fill in the blanks", by putting something into that FrameLayout:
If you want each "screen/view" to be an Activity, you would use the aforementioned layout file in setContentView(), then manually inflate (or instantiate directly in Java) whatever "some blanks" are. You would call addView() on the FrameLayout to "fill in the blanks" with whatever you inflated. If you wanted, most of the logic could be bundled up in a base class, with subclasses overriding some gimmeTheBlanksPlease() method that supplies what is to be poured into the FrameLayout.
If you want each "screen/view" to be a Fragment, you would use the aforementioned layout file in onCreateView(), then manually inflate (or instantiate directly in Java) whatever "some blanks" are. Again, you would pour that stuff into the FrameLayout via addView(), and once again most of this codde could be implemented in an abstract base class.
There are more complex solutions (e.g., custom ViewGroup) as well.
The only simpler solution is if the "90% common portions of this UI flow" can be defined in ~1 layout file, you can use the <include> tag for composition of layouts. You'd have one common layout with the common elements, which would be included into the per "screen/view" layout and used at runtime. Again, you'd probably have an abstract base Activity or Fragment that knew about the common stuff. However, this gets messy if the "90%" would wind up being split among a whole bunch of layout files, just because of how the XML and positioning worked.

Group of Views (controls) on multiple screens

I am working on an Android project where a group of buttons needs to show on the bottom of every screen (activity) in the application. The group of buttons are basically a navigation bar. I want to know the best way to do this without creating new buttons for every activity. I have been around programming (C++/C#) for many years but am pretty new to Android and Java so if someone can point me in a general direction, it would be appreciated.
Thanks.
I bet you need to use "include" tag for xml layouts. It's the best when you need to reuse some UI components. See http://www.curious-creature.org/2009/02/25/android-layout-trick-2-include-to-reuse/ for the examples and description.
To elaborate on Konstantin's answer, after you've used include, you'll need to bind actions to these buttons.
If the buttons should have the same action regardless of the activity they are in, use the include tag to create their layout and then create a parent NavigationActivity (or whatever else you want to call it) class from which all your other activites will inherits.
In the parent NavigationActivity class' onCreate method, you can set up the onClickListener (and other needed stuff) for the buttons.

Categories

Resources