Android implement navigation - android

I am trying to learn Android development and have stumbled across the following thing I cannot solve.
I have imported Bottom Bar Navigation via Gradle to my app and have managed to set it up according to instructions. Here is what my screen looks like now.
As you can see, I have three tabs at the bottom that I am trying to use for navigation. The problem however is, that even though I know how to detect which element has been clicked via following:
mBottomBar.setItemsFromMenu(R.menu.bottombar_menu, new OnMenuTabClickListener() {
#Override
public void onMenuTabSelected(#IdRes int menuItemId) {
if (menuItemId == R.id.bb_menu_favorites) {
// The user selected item number one.
}
}
#Override
public void onMenuTabReSelected(#IdRes int menuItemId) {
if (menuItemId == R.id.bb_menu_favorites) {
// The user reselected item number one, scroll your content to top.
}
}
});
I have no idea how to actually perform the navigation request - e.g. when user moves to different tab, I want to show my other screen instead of Hello World! that you can see at the moment.
I believe that for this I need to actually change my activity_main.xml file as currently it looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
...
tools:context="com.example.robert.testproject.MainActivity">
<include layout="#layout/page_import"/>
</RelativeLayout>
This is where I have ended. As far as my understanding goes, I somehow need to use Intent (correct me if I am wrong) for the navigation purposes, but I am not quite sure how to handle this.
Any help in this matter - switching views, would be more than appreciated.

Use a Fragment for each bottom tab (3 Fragments for 3 views). Have a container layout(maybe a FrameLayout) in the Activity. Each Fragment will have different layouts. Replace the fragments based on what the user has tapped on the bottom bar.

Related

Android Placing Text (bar) at bottom of Application

I want to be able to display text (a bar if you will) at the bottom of my application dynamically to indicate if the the application is online or not (an endless issue for users currently). I don't need for this to have any action, but I do need it to be able to control it displaying or not based on them toggling between online and offline mode. So the split action bar is not what I am looking for.
Not enough reputation points to post an example. Doh. Here is the link:
Ugly example, look at bottom
Something simple is fine - I am good with XML based or dynamic (though I will also need to hide and show it dynamically).
Thanks!
Dynamic solution. Define your method that the activity will use to hide / display your bottom TextView (text bar?).
In your XML:
<TextView
android:id="#+id/text_bar"
...
...
android:visibility="gone"/>
In your activity:
public MyActivity extends Activity{
private TextView mTextBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_activity_xml);
...
...
mTextBar = (TextView) findViewById(R.id.text_bar);
}
public void updateVisibility(boolean visible){
int visibility = (visible) ? View.VISIBLE: View.GONE;
mTextBar.setVisibility(visibility);
}
}
Initially, the TextView (your text bar) has it's visibiity set to gone. Dynamically, when you want to show it call the updateVisibility(true) method to show it, and updateVisibility(false) to hide it.
Since I'm not sure how you are handling the check for the network status (in queries, in the onCreate, etc). I don't know what you intended to do for the TextView. If you need advice on how to position the TextView on the bottom of the screen I can provide example code for that as well.

Android splitview/region presenter with MvvmCross

My goal is to create an Android UI window that displays three regions: navigation, main, and popup. The navigation and main region will function as a split view. The popup region will be centered in the screen and overlay the other two regions; it will also only be visible part of the time. Ideally, I'd like these regions to host fragments that are dynamically changed to display different layouts and view models based on user interaction. And, all of this should be accomplished without breaking the MvvmCross bindings.
I've got something that works, but it feels a bit hacked together. The current implementation most closely follows resource 1 below. Each region has a dictionary. All of the fragments are registered with a dictionary based on their target region. This is done from the activity. The activity also takes care of inflating each layout and associating it with the correct view model. I’d like to change this so that MvvmCross can do more of the work.
Is it possible to create a custom presenter, in Android, that is a mix between the dynamic fragment layout from resource 2 and the iOS custom presenter shown in resource 3? Just to clarify, I want to specifically define where each region will be displayed using a layout. Then I want to dynamically fill the content, of each region, with different layouts and their associated view models, at runtime.
Resource 1: MvvmCross v3 Fragment Sample
https://github.com/slodge/MvvmCross-Tutorials/tree/master/Fragments
See: “FragmentSample.UI.Droid/Views/TitlesView.cs” and “FragmentSample.UI.Droid/Setup.cs”
Resource 2: N=26 - Androids… down at Fragment Rock
http://www.youtube.com/watch?feature=player_embedded&v=uQT3_WXQQr0
Dynamic Fragment Layout created explained at 26:25 – 32:10
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="#+id/subframe1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="#+id/dubframe1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
(In addition to being an extremely helpful video, of all the N+1 videos I've had a chance to watch, this one has the best intro!)
Resource 3: N=24 - Split View
http://www.youtube.com/watch?feature=player_embedded&v=PpeysFIINcY
iOS SplitPresenter created at 11:25 – 15:05
public class SplitViewController : UISplitViewController
{
public SplitViewController()
{
this.ViewControllers = new UIViewController[]
{
new UIViewController(),
new UIViewController(),
};
}
public void SetLeft(UIViewController left)
{
this.ViewControllers = new UIViewController[]
{
left,
this.ViewControllers[1]
};
}
public void SetRight(UIViewController right)
{
this.ViewControllers = new UIViewController[]
{
this.ViewControllers[0],
right,
};
}
}
I created a small example project on GitHub that demonstrates how to create multiple regions.
This shows the three regions: Navigation, Main and Popup. The location, size and shape of each region is defined in one layout file. The content is defined, with separate layout files and view models, for each region and is dynamically changed at runtime. MvvmCross bindings still work with each individual view model.
EDIT
I added a more robust solution example on github. This allows the ViewModel to be opened in the standard way. The MultiRegionPresenter handles matching up the view with the correct region by looking at a tag in the view. Views are now tagged with their intended region like this: [Region(Resource.Id.MainRegion)].
The new example project is located here: MultiRegionPresenter Example

ProgressBar in an ActionBar, like GMail app with Refresh

I would like to do the same thing than the GMail application on Honeycomb tablets.
When you click on the Refresh button, the icon is replaced by a ProgressBar.
How can I do this?
Thanks
Ok, I tried what Cailean suggested but it didn't work for me. Every time I want to revert indeterminate progress to the original button it becomes unclickable, I used this layout for the progress
(actionbar_refresh_progress.xml)
<?xml version="1.0" encoding="utf-8"?>
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center"/>
and this one to revert to the button
(actionbar_refresh_button.xml)
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/ic_menu_refresh_holo_light"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
my code was:
private void setRefreshing(boolean refreshing) {
this.refreshing = refreshing;
if(refreshMenuItem == null) return;
View refreshView;
LayoutInflater inflater = (LayoutInflater)getActionBar().getThemedContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(refreshing)
refreshView = inflater.inflate(R.layout.actionbar_refresh_progress, null);
else
refreshView = inflater.inflate(R.layout.actionbar_refresh_button, null);
refreshMenuItem.setActionView(refreshView);
}
After browsing the source of the Google IO app, especially this file: http://code.google.com/p/iosched/source/browse/android/src/com/google/android/apps/iosched/ui/HomeActivity.java i found another easier way.
Now I need only the first layout with progress and the working method looks like this:
private void setRefreshing(boolean refreshing) {
this.refreshing = refreshing;
if(refreshMenuItem == null) return;
if(refreshing)
refreshMenuItem.setActionView(R.layout.actionbar_refresh_progress);
else
refreshMenuItem.setActionView(null);
}
Menu item definition:
<item android:id="#+id/mail_refresh"
android:title="Refresh"
android:icon="#drawable/ic_menu_refresh_holo_light"
android:showAsAction="always"/>
I hope someone finds this useful.
Gmail does this using an action view for its "refresh in progress" state. Invoking a refresh is done using the standard action button/onMenuItemSelected path.
When you enter your refreshing state, set the action view of the refresh MenuItem to a ProgressBar. (Create it programmatically, inflate it from a layout, use actionLayout in the menu xml as CommonsWare suggests, whatever you prefer.) When you exit your refreshing state, set the action view back to null while keeping a reference to it so you can set it back again the next time you refresh. You can hang onto a reference to the MenuItem after you inflate the menu and changes to it later will be reflected in the action bar.
This approach has some advantages over using a full-time action view and managing other details of the state change yourself. An action view completely replaces the generated action button for a menu item, effectively blocking the user from being able to send the usual onMenuItemSelected events for refresh while a refresh is already in progress. One less thing to handle and the action view can stay completely non-interactive.
You could probably do something clever with an ActionProvider in API 14+ to encapsulate the whole process a bit more but the above ends up being pretty simple.
Assuming that you already have your menu item setup, you'll need to start by creating two new layouts. One that contains the layout for the normal refresh button, and another that contains the progressbar.
Once you have them, call the following piece of code to switch between the two layouts. It'll be up to you to decide exactly when it needs to be called a second time in order to switch it back to the refresh icon.
private void doRefresh(Boolean refreshing, MenuItem menuItem)
{
View refreshView;
LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(refreshing)
refreshView = inflater.inflate(R.layout.actionbar_indeterminate_progress, null);
else
refreshView = inflater.inflate(R.layout.refresh_icon, null);
menuItem.setActionView(refreshView);
}
Use the following layout as the action view for the action bar menu item.
actionbar_refresh_progress.xml
<FrameLayout
android:layout_height="wrap_content"
android:layout_width="#dimen/abc_action_button_min_width"
android:minWidth="#dimen/abc_action_button_min_width">
<ProgressBar
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center"
style="?indeterminateProgressStyle" />
</FrameLayout>
Then
menuItem.setActionView(R.layout.actionbar_refresh_progress);
Works across Gingerbread and the rest like a charm. Note that I have used dimension from support action bar for compatibility. You can use #dimen/action_button_min_width instead for ICS and up.
Source: https://code.google.com/p/iosched/source/browse/android/res/layout/actionbar_indeterminate_progress.xml?r=f4fd7504d43b25a75cc23b58d6f844f3553b48c3

My Listview doesnt scroll - and I DONT use scrollview

Firstly I have a tabview with multiple activities, three of which are listviews.
I created the first one - equipment and that worked a treat. I then created the rest by cut/paste the files in eclipse and renaming the files and calling the new files.
Problem - Equipment has stopped scrolling.
Ive even reduced it to its component parts and removed the list prepopulation with a simply options1-5 but it still refuses to move up or down.
IN other windows, even if the list is not fully populated, the window can be grabbed and the contents will scroll up/down and when released will pop back to nromal view at the top of the screen.
Ive compared line by line and for the life of me cant figure out why this is not working.
Code below:
public class harpcsEquipment extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView (R.layout.tab_harp_equipment);
// Got the entire Equipment list and now we populate the Listview
String[] listitems = {"Option 1","Option 2","Option 3","Option 4","Option 5"};
ListView lv = (ListView) findViewById(R.id.list);
lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listitems));
//#Override
protected void onResume()
{
super.onResume();
// NOW WE ADD DATA TO THE TEMPLATE
//populateXMLCharacter();
}
}
tab_harp_equipment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
the listview was called equiplist but changing to the default name made no difference...
Any help would be greatly appreciated!
Regards
Jason
I have a lot of code (in this and the cloned classes and the clones work but the parent does not...) I can copy paste the entire lot but since the only difference is the data that is being pasted and the number of fields I am displaying (thus different layout files called in the arrayadapter), but since the basic demo code above doesnt work, Im at a loss...
OK, better success here after much testing.
I have TWO icons on a home screen (think google plus icon screen if it helps).
Two icons open a tabhost each - there are 8 tabs and fitting them all on one tab is just messy.
All tabs on the first tabhost work. Listviews scroll in them.
All listviews on the second tab do NOT work.
Copying the text:
intentE = new Intent().setClass (this, harpcsEquipment.class);
specE = tabHostE.newTabSpec("Equipment").setIndicator("Equipment",
res.getDrawable(R.drawable.shield)).setContent(intentE);
tabHostE.addTab(specE);
from one tabActivity to the next works fine - the equipment listview opens and scrolls.
So the problem is the tabActivity.
Does anyone know why a second tabactivity will not allow a listview to scroll inside it?
OK, Resolved.
TabActivity has a flaw/undocumented feature/etc.
It wont allow you to get full functionality form a second TabActivity inside a program.
So in the calling java program, when I use the intent to call the program that creates the tabhost, I simply putExtra("tab", "1") or putExtra("tab", "2").
Inside the program I simply get the Extra and if tab==1 then load tabhost with one set of Tabhosts intents, and else load it with another set of tabhosts intents.
Damn tabactivity... Whoda thunk it huh?
Hope this helps someone else in the future.

tab bar hiding issue android

I'm new to android,I'm using tabHost adding some tabs to it,its working quite fine but when i rotate my device in landscape mode it also work there fine but i don't need tab bar there because it covers much space and i also have google ads so both of them cover half of the screen and leave a little space for user to interact.All i need is a solution to somehow hide tab bar just like we can do it in iphone to make a bit room for user to interact.I need some solution urgent.Thanks
I think you should wrap your tab widget in any ViewGroup such as LinearLayout or RelativeLayout, and create a static function in your tabActivity to show/hide this wrapper, Here's a little code might be helpful for you.
<LinearLayout
android:id="#+id/popupTabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<TabWidget android:id="#android:id/tabs"
android:layout_height="wrap_content"
android:layout_width="fill_parent"></TabWidget>
</LinearLayout>
Now your tab activity should do something like this.
public class TabsView extends TabActivity {
public static LinearLayout popupTabs ;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
popupTabs = (LinearLayout) findViewById(R.id.popupTabs);
// Your other code
//............
//............
}
// Show Tabs method
public static void showTabs(){
popupTabs.setVisibility(ViewGroup.VISIBLE);
}
// Hide Tabs method
public static void hideTabs(){
popupTabs.setVisibility(ViewGroup.GONE);
}
}
Now you can call this method statically from any location in your code like this
// hide tab from any activity
TabsView.showTabs();
// hide tab from any activity
TabsView.hideTabs()
For Hide
mTabHost.getTabWidget().setVisibility(View.GONE);
For Visible
mTabHost.getTabWidget().setVisibility(View.VISIBLE);
The simplest way would be to create a second version of your layout.xml file which doesn't include the TabHost and put it in a resource folder named 'layout-land' (the 'land' suffix is short for 'landscape'). Please see this SDK article for more information.
Apart from doing what Reuben is telling you would be to animate the transition between both so that the change would be a bit smoother.

Categories

Resources