Use Tab with new ToolBar (AppCompat v7-21) in mvvmcross

I have use support_v7 Toolbar as ActionBar, but i getting problem to add tabs in my activity. Is there any example to add tab with toolbar. I took a look at http://blog.ostebaronen.dk/2013/11/getting-support-v7-working-with.html

-------------Problems Reply------------

I works just the same as normal Android apps. Use the layouts that Gabriele Mariotti's link has. To make the viewpager work with bindings in MvvmCross you need to use something like this: https://github.com/MvvmCross/MvvmCross-AndroidSupport/blob/master/Cirrious.MvvmCross.Droid.Support.V4/MvxFragmentStatePagerAdapter.cs

For better readability: https://gist.github.com/martijn00/23b00172af9e2c798f3d

Here is some code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
app:tabGravity="center"
app:tabMode="scrollable" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

public class SomeFragment : MvxFragment<SomeViewModel>
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = base.OnCreateView(inflater, container, savedInstanceState);

var viewPager = view.FindViewById<Android.Support.V4.View.ViewPager>(Resource.Id.viewpager);
if (viewPager != null)
{
var fragments = new List<MvxViewPagerFragmentAdapter.FragmentInfo>
{
new MvxViewPagerFragmentAdapter.FragmentInfo
{
FragmentType = typeof(SomeFragment1),
Title = "",
ViewModel = ViewModel.ViewModelSomething1
},
new MvxViewPagerFragmentAdapter.FragmentInfo
{
FragmentType = typeof(SomeFragment2),
Title = ViewModel.ViewModelPopular.TextSource.GetText("Title"),
ViewModel = ViewModel.ViewModelSomething2
},
new MvxViewPagerFragmentAdapter.FragmentInfo
{
FragmentType = typeof(SomeFragment3),
Title = ViewModel.ViewModelContributors.TextSource.GetText("Title"),
ViewModel = ViewModel.ViewModelSomething3
}
};
viewPager.Adapter = new MvxViewPagerFragmentAdapter(Activity, Activity.SupportFragmentManager, fragments);
}

var tabLayout = view.FindViewById<TabLayout>(Resource.Id.tabs);
tabLayout.SetupWithViewPager(viewPager);

return view;
}
}

public class MvxFragmentStatePagerAdapter
: FragmentStatePagerAdapter
{
private readonly Context _context;

public IEnumerable<FragmentInfo> Fragments { get; private set; }

public override int Count
{
get { return Fragments.Count(); }
}

protected MvxFragmentStatePagerAdapter(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
}

public MvxFragmentStatePagerAdapter(
Context context, FragmentManager fragmentManager, IEnumerable<FragmentInfo> fragments)
: base(fragmentManager)
{
_context = context;
Fragments = fragments;
}

public override Fragment GetItem(int position)
{
var fragmentInfo = Fragments.ElementAt(position);
var fragment = Fragment.Instantiate(_context,
FragmentJavaName(fragmentInfo.FragmentType));
((MvxFragment)fragment).ViewModel = fragmentInfo.ViewModel;
return fragment;
}

protected static string FragmentJavaName(Type fragmentType)
{
var namespaceText = fragmentType.Namespace ?? "";
if (namespaceText.Length > 0)
namespaceText = namespaceText.ToLowerInvariant() + ".";
return namespaceText + fragmentType.Name;
}

public override ICharSequence GetPageTitleFormatted(int position)
{
return new Java.Lang.String(Fragments.ElementAt(position).Title);
}

public class FragmentInfo
{
public string Title { get; set; }

public Type FragmentType { get; set; }

public IMvxViewModel ViewModel { get; set; }
}
}

Category:android Views:1 Time:2018-12-04

Related post

  • using tabs with a webview 2011-04-01

    I am trying to use tabs with a webview but I cant seem to get it to work together, i can only get one or the other to display depending on where i put the webview but not both at the same time. here is my main.xml <?xml version="1.0" encoding="utf

  • Using Tabs with Views 2012-04-15

    I have a little problem using Tabs with Views. First I just copied the sample code where Tabs are used with activitys: My LayoutFile looks like this: <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/a

  • Using template with custom toolbar created in Word 2003 in Word 2010 2013-01-13

    We have hundreds of document shells that are all attached to a style.dot that was created in Word 2003. The styles.dot has a highly complex toolbar with all needed styles, document property functionality, symbols shortcuts, macros for creating comple

  • Emacs 23 built-in python.el indentation broken using tabs with width 4 2011-02-23

    I've been using the version of python.el found here for a couple of years in Emacs 23 without incident. I decided to try the stock python.el, and ran into a strange issue: When using tabs for indentation and a tab width of 4, the stock python.el will

  • Is it wrong to use auto_ptr with new char 2008-11-04

    If I declare a temporary auto deleted character buffer using std::auto_ptr<char> buffer(new char[n]); then the buffer is automatically deleted when the buffer goes out of scope. I would assume that the buffer is deleted using delete. However th

  • how to check consequence of using free() with new [] 2011-10-04

    A process is crashing with SIGSEV, and the backtraces indicate memory corruption. Valgrind report indicates that there are some 'Mismatched free', i.e memory allocated with new[] is being released with free(). I found the following information from c

  • Using tabs with jquery 2011-02-01

    I'm using the tabs control in jquery ui. I add new tabs dynamically based on some kind of logic with the following code: $("#div_Tabs").tabs("add", "/Game/PlayGame?matchID=" + result.MatchID, "Play with " + userName); My problem is that when the user

  • using tabs with jQuery - Clear tab content 2011-08-05

    I'm using jquery tabs in my web application. The tabs are created dynamically depending on the user query result. I have a couple issues: My tab is pointing to <div> content with the corresponding id. When the user clicks the tab, the content i

  • Exception using CopyToDataTable with "new {..}" LINQ query 2009-07-02

    From this code I can call bmwCars.CopyToDataTable() as I expected. var bmwCars = from car in dataTable.AsEnumerable() where car.Field<string>("Make").ToLower().Equals("bmw") select car; But when I have change some statement of code to below, I

  • What's the outcome if I use free with new or delete with malloc? 2010-03-28

    It is a compiler error or runtime error? The code below can be compiled! class Base{ void g(); void h(); }; int main() { Base* p = new Base(); free(p); return 0; } However it can't be compiled with a virtual function if I declare the class Base like

  • Using QSharedPointer with new[] yields "Mismatched free() / delete / delete[]" in valgrind 2011-10-24

    I have the following code: QPair<QSharedPointer<unsigned int>, int> someclass::somefunction() { int siz = data_size(); QSharedPointer<unsigned int> buffer(new unsigned int[siz]); // Fill the buffer... return qMakePair(buffer, siz);

  • How to edit the "Home"tab with custom toolbar 2014-07-28

    Hi All, I have recently moved from Outlook 2007 to 2010. I like to use TwinBox to review my twitter feed and it used to work great on 2007 where I could see the tweet ribbon displaying on the main Outlook mail page. Now in 2010 it is moved to the add

  • OpenGL ES 2.0: Using glBufferData with new vertex data size 2011-09-04

    I have an array of vertex attributes GLfloat *vxData. I've bound both GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER with vxData and the correct index data, and the initial vertices render successfully. At each render step I do: glBindBuffer(GL_ARRAY_BU

  • Unable to find constructor when using varargs with new class 2012-03-15

    I got a hibernate exception Caused by: org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class My query is "Select new example.ReportField(r.memberName, r.address) from Member r" public class ReportField { public

  • Zend Studio 9 tabbing with new line 2012-04-05

    $arr = array( ); It looks like this when i press enter for a new line when I'm defining an array. It is always 2 tabs instead of 1. I didn't have this problem in Zend Studio 8. Any ideas how to fix this? --------------Solutions------------- Windows W

  • neverending tabs with new outlook.com 2012-11-26

    if I open outlook.com that's one tab, if I then go to onedrive that's another tab, if I open a doc in onedrive that's another tab, if I then go back to outlook.com that a second outlook tab, if I then go to excel that's another tab, if I go back to o

  • Example of using Android tabs with Views instead of Activities? 2010-06-04

    The Android Developers TabWidget tutorial says the following: "You can implement your tab content in one of two ways: use the tabs to swap Views within the same Activity, or use the tabs to change between entirely separate activities." The tutorial g

  • Is there a way with IE8 to quit using tabs? 2012-02-26

    Can I quit using tabs with IE8? --------------Solutions------------- Sure. I hate tabs. Tools | Internet Options | General Tab | Tabs Section | Settings Button. Uncheck the first box: Enable Tabbed Browsing. Close and open IE and you're done.

  • GetAdapterAddresses function with NEW instead of MALLOC 2011-11-24

    I would use the GetAddressesInfo() function of windows to get some informations about the adapters of the computer. In this MSDN page there is a big example of how to use it but I'm using C++ so I would stick with the NEW keyword and not MALLOC (C na

  • How to space text like using tab on website? 2012-03-30

    I just got another assignment for web design. And I was curios how to space text like this. The issue here is not the heading nor the text on the left. I have problem with the time on the right. We are forbidden to edit html which looks like this:

  • How to use customized Quick Access Toolbar with default office menu tabs 2014-11-06

    I am making an template in Word 2010. What I want to do is to make a template which has a new ribbon tab with 4 groups in addition to the default word tabs. The template also should have a quick access toolbar with 4 different image icons correspondi

  • Accessing 2010 add-ins tab with 2003 protected template toolbar problem 2013-05-27

    I have a template for Word 2003 with a custom toolbar which calls a load of macros to format a style-protected document. This works well for most users who use 2003. Some users are using 2007 and some 2010, and so it needs to also work for them. I wa

  • On iOS 7, pushing a controller with a toolbar leaves a gap of unusable space if it's ultimately contained within a tab bar controller 2013-12-14

    In my iOS app, my window's rootViewController is a tab bar controller with the a hierarchy like this: UITabBarController UINavigationController 1 FirstContentController UINavigationController 2 ... UINavigationController 3 ... ... When the user taps

  • A secure site does not open in a new tab with Shift-Ctrl IE8 2014-02-10

    IE Version: 8.006001018702 Cipher Strength: 256 bit Product ID: 01402-482-4790762-71899 Update Versions: 0 The issue occurs with the following site: HyperText Transfer Protocol with Privacy TLS 1.0, RC4 with 128 bit encryption (High); RSA with 1024 b

  • Word 2007 : change macro listing with the Toolbar Commands group in the Add-Ins tab in the Ribbon 2014-12-07

    Hi, In Word 2003 I modified 1. the Standard and Formatting toolbars (add, delete or move icons) 2. the drop-down menus themselves ("File", "Format", etc), adding, deleting and moving commands 3. the right-click menus (for instance, add the "Replace..

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.077 (s). 11 q(s)