Is it possible? supported?
I want to make an app that hosts widgets in fragments, I know how to do it on activity but don't know if it works with fragments.
Im sure you mean AppWidgets, so take a look at this
https://github.com/DagW/FragmentHomescreen
It contains a complete example project for adding widgets to fragments in a viewpager.
It also contains code for adding appwidgets programatically.
Related
I have an Android app with two classes:
-MainActivity
-SecondActivity
I have also two layouts for these classes (they are pretty similar).
I want to switch between these activities by 'shifting' to the right or to the left.
All materials I find are about switching by button.
Anyone would recommend using Fragments and ViewPager instead of Activity since you want sliding action and make use of the Android TabLayout.
Here is a tutorial that you can draw a basic idea from.
I want to make something like this in my android app
With 2 or 3 activities or more. I don't want to use visible tabs with names. I just want when i slide through a new activity with its own layout appear, a totally different screen. I've read about viewpager and pageradapter, but i' m a little confused. What do you think is the best way to do it?
This is what you need, just follow this tutorial http://www.androidhive.info/2015/09/android-material-design-working-with-tabs/
You dont even need multiples activities.
You can actually create a swiping activity in android studio.
Goto:
File -> New -> Activity -> Tabbed Activity and choose Navigation Style to be Swipe Views.
Android Studio will do the rest. Then you can change the fragments according to your need.
EDIT:
This is a nice example that demonstrate using Activity with ViewPager.
Android PagerView between Activities
I'm developing an application and I want to place two activities in a tabbed layout. I need the ability for the first activity to send an intent and programmatically switch to the second tabbed activity. This seems possible and is outlined in other posts:
Launching activities within a tab in Android
However, this approach doesn't seem advisable and it makes use of ActivityGroup, which is now deprecated. Can anyone recommend a stable solution that would meet my design needs?
You may want to take a look at ViewPager from the support library, coupled with https://github.com/JakeWharton/Android-ViewPagerIndicator/blob/master/library/src/com/viewpagerindicator/TabPageIndicator.java
It will produce a tab-like interface that you can swipe through. You can explicitly change which tab is being shown by calling viewPager.setCurrentItem(int).
I am not sure if this is the right way to do it. I have a ChatActivity using FrameLayout in frame.xml. This activity needs to be reused across 5 activities. Is there anyway to do a code reuse? This acitivty runs independently of other activities.
For example, in activity A, which uses main.xml, I want ChatActivity and frame.xml to be included. What is the best way to achieve this besides merging the ChatActivity and frame.xml into activity A and main.xml? Merging the activities would mean that I have to copy and paste codes 5 times into different activities. I am not sure if this is the right way...
You cannot "include" an Activity to another Activity. Since your Activity has a basic functionality that all your other Activities use, you could have all your Activities extend this basic Activity.
The best way though for you would be to use Fragments and the compatibility library.
Regarding layouts, you can have reusable ones and import them to your current layout using include.
Hope this helps!
Use Fragments. you can create one Fragment and use the same in all activities. Fragments have their own view. Look at the following link for fragment.
http://developer.android.com/guide/topics/fundamentals/fragments.html
you can use fragments before 3.0 by including compatibility library.
http://android-developers.blogspot.com/2011/03/fragments-for-all.html
I android you can reuse xml files by using the include tag like
<include layout="#layout/okcancelbar_button" android:id="#+id/okcancelbar_ok"/>
To share functionalites of an activity with other activities, create a base activity with common functionalites and make the other activities extend from it.
Hallo,
Any idea where I can find a simple tabs example?
The Android Developers Hello Views Tab Layout example only details how to use separate Activities for each Tab.
I would like to use tabs to extend a screen of settings without scrolling, i.e. there are too many options for a single screen, so I'd like to split them over two tabs, but still handle them in the same Activity.
Each tab can refer to a separate layout file if that is how it needs to be done,
TIA,
-Frink
if your tabs don't need to be dynamic you can just load the views in the xml file. Just like in this example http://developer.android.com/guide/tutorials/views/hello-tabwidget.html
In your tabhost instead of passing an intent you can pass a viewID