Permalink
Browse files

Tabs added on main screen

  • Loading branch information...
iks111 committed May 7, 2017
1 parent c723367 commit db3594f47d10ea543d9a9d2d4869097455590626
@@ -3,22 +3,51 @@
using Android.Content;
using Android.Widget;
using Android.OS;
using ActionBar = Android.App.ActionBar;
namespace MoneyBack
{
[Activity(Label = "@string/ApplicationName", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
private Button _btnPeople;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
InitializeUserControls();
InitializeTabs();
}
private void InitializeTabs()
{
this.ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
var tab = this.ActionBar.NewTab();
tab.SetText("People");
AddTab("People", new PeopleListFragment());
}
void AddTab(string tabText, Fragment view)
{
var tab = this.ActionBar.NewTab();
tab.SetText(tabText);
// tab.SetIcon(Resource.Drawable.ic_tab_white);
// must set event handler before adding tab
tab.TabSelected += delegate (object sender, ActionBar.TabEventArgs e)
{
var fragment = this.FragmentManager.FindFragmentById(Resource.Id.tabFragmentsContainer);
if (fragment != null)
e.FragmentTransaction.Remove(fragment);
e.FragmentTransaction.Add(Resource.Id.tabFragmentsContainer, view);
};
tab.TabUnselected += delegate (object sender, ActionBar.TabEventArgs e) {
e.FragmentTransaction.Remove(view);
};
this.ActionBar.AddTab(tab);
}
protected override void OnStart()
@@ -29,18 +58,11 @@ protected override void OnStart()
protected override void OnResume()
{
base.OnResume();
InitializeUserControlsEvents();
}
protected override void OnPause()
{
base.OnPause();
DetatchUserControlsEvents();
}
private void DetatchUserControlsEvents()
{
_btnPeople.Click -= _btnPeople_Click;
}
protected override void OnStop()
@@ -53,16 +75,6 @@ protected override void OnDestroy()
base.OnDestroy();
}
private void InitializeUserControls()
{
_btnPeople = this.FindViewById<Button>(Resource.Id.btnPeople);
}
private void InitializeUserControlsEvents()
{
_btnPeople.Click += _btnPeople_Click;
}
private void _btnPeople_Click(object sender, EventArgs e)
{
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="packages\Xamarin.Build.Download.0.4.2\build\Xamarin.Build.Download.props" Condition="Exists('packages\Xamarin.Build.Download.0.4.2\build\Xamarin.Build.Download.props')" />
<Import Project="packages\Xamarin.Build.Download.0.4.3\build\Xamarin.Build.Download.props" Condition="Exists('packages\Xamarin.Build.Download.0.4.3\build\Xamarin.Build.Download.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -52,18 +52,6 @@
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
<Reference Include="Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Xamarin.Android.Support.Compat.25.1.1\lib\MonoAndroid70\Xamarin.Android.Support.Compat.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xamarin.Android.Support.Core.UI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Xamarin.Android.Support.Core.UI.25.1.1\lib\MonoAndroid70\Xamarin.Android.Support.Core.UI.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xamarin.Android.Support.v7.RecyclerView, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Xamarin.Android.Support.v7.RecyclerView.25.1.1\lib\MonoAndroid70\Xamarin.Android.Support.v7.RecyclerView.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Entities\Person.cs" />
@@ -72,7 +60,7 @@
<Compile Include="Orm\IRepository.cs" />
<Compile Include="Orm\Repository.cs" />
<Compile Include="PeopleActivity.cs" />
<Compile Include="PeopleListActivity.cs" />
<Compile Include="PeopleListFragment.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SQLite.cs" />
@@ -113,16 +101,10 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\Xamarin.Build.Download.0.4.2\build\Xamarin.Build.Download.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Xamarin.Build.Download.0.4.2\build\Xamarin.Build.Download.props'))" />
<Error Condition="!Exists('packages\Xamarin.Build.Download.0.4.2\build\Xamarin.Build.Download.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Xamarin.Build.Download.0.4.2\build\Xamarin.Build.Download.targets'))" />
<Error Condition="!Exists('packages\Xamarin.Android.Support.Compat.25.1.1\build\MonoAndroid70\Xamarin.Android.Support.Compat.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Xamarin.Android.Support.Compat.25.1.1\build\MonoAndroid70\Xamarin.Android.Support.Compat.targets'))" />
<Error Condition="!Exists('packages\Xamarin.Android.Support.Core.UI.25.1.1\build\MonoAndroid70\Xamarin.Android.Support.Core.UI.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Xamarin.Android.Support.Core.UI.25.1.1\build\MonoAndroid70\Xamarin.Android.Support.Core.UI.targets'))" />
<Error Condition="!Exists('packages\Xamarin.Android.Support.v7.RecyclerView.25.1.1\build\MonoAndroid70\Xamarin.Android.Support.v7.RecyclerView.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Xamarin.Android.Support.v7.RecyclerView.25.1.1\build\MonoAndroid70\Xamarin.Android.Support.v7.RecyclerView.targets'))" />
<Error Condition="!Exists('packages\Xamarin.Build.Download.0.4.3\build\Xamarin.Build.Download.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Xamarin.Build.Download.0.4.3\build\Xamarin.Build.Download.props'))" />
<Error Condition="!Exists('packages\Xamarin.Build.Download.0.4.3\build\Xamarin.Build.Download.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Xamarin.Build.Download.0.4.3\build\Xamarin.Build.Download.targets'))" />
</Target>
<Import Project="packages\Xamarin.Build.Download.0.4.2\build\Xamarin.Build.Download.targets" Condition="Exists('packages\Xamarin.Build.Download.0.4.2\build\Xamarin.Build.Download.targets')" />
<Import Project="packages\Xamarin.Android.Support.Compat.25.1.1\build\MonoAndroid70\Xamarin.Android.Support.Compat.targets" Condition="Exists('packages\Xamarin.Android.Support.Compat.25.1.1\build\MonoAndroid70\Xamarin.Android.Support.Compat.targets')" />
<Import Project="packages\Xamarin.Android.Support.Core.UI.25.1.1\build\MonoAndroid70\Xamarin.Android.Support.Core.UI.targets" Condition="Exists('packages\Xamarin.Android.Support.Core.UI.25.1.1\build\MonoAndroid70\Xamarin.Android.Support.Core.UI.targets')" />
<Import Project="packages\Xamarin.Android.Support.v7.RecyclerView.25.1.1\build\MonoAndroid70\Xamarin.Android.Support.v7.RecyclerView.targets" Condition="Exists('packages\Xamarin.Android.Support.v7.RecyclerView.25.1.1\build\MonoAndroid70\Xamarin.Android.Support.v7.RecyclerView.targets')" />
<Import Project="packages\Xamarin.Build.Download.0.4.3\build\Xamarin.Build.Download.targets" Condition="Exists('packages\Xamarin.Build.Download.0.4.3\build\Xamarin.Build.Download.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
@@ -13,7 +13,6 @@ namespace MoneyBack
public class PeopleActivity : Activity
{
private Button _btnSavePerson;
private Button _btnPeopleList;
private EditText _inputName;
private EditText _inputLastName;
@@ -43,16 +42,9 @@ protected override void OnResume()
private void InitializeUserControlsEvents()
{
_btnSavePerson.Click += _btnSavePerson_Click;
_btnPeopleList.Click += _btnPeopleList_Click;
}
private void _btnPeopleList_Click(object sender, EventArgs e)
{
var intent = new Intent(this, typeof(PeopleListActivity));
StartActivity(intent);
}
private async void _btnSavePerson_Click(object sender, EventArgs e)
{
var name = _inputName.Text;
@@ -91,7 +83,6 @@ protected override void OnPause()
private void DetatchUserControlsEvents()
{
_btnSavePerson.Click -= _btnSavePerson_Click;
_btnPeopleList.Click -= _btnPeopleList_Click;
}
protected override void OnStop()
@@ -109,7 +100,6 @@ protected override void OnDestroy()
private void InitializeUserControls()
{
_btnSavePerson = this.FindViewById<Button>(Resource.Id.btnSavePerson);
_btnPeopleList = this.FindViewById<Button>(Resource.Id.btnPeopleList);
_inputName = this.FindViewById<EditText>(Resource.Id.inputName);
_inputLastName = this.FindViewById<EditText>(Resource.Id.inputLastName);
@@ -1,29 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using MoneyBack.Entities;
using MoneyBack.Orm;
namespace MoneyBack
{
[Activity(Label = "@string/peopleListTitle")]
public class PeopleListActivity : ListActivity
public class PeopleListFragment : ListFragment
{
private List<Person> _peopleList;
protected override async void OnCreate(Bundle savedInstanceState)
public override void OnActivityCreated(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
base.OnActivityCreated(savedInstanceState);
var repo = new Repository<Person>();
InitializePeopleList(savedInstanceState);
}
protected async void InitializePeopleList(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
_peopleList = await GetPeopleAsync();
this.ListAdapter = new ArrayAdapter<Person>(this, Android.Resource.Layout.SimpleListItem1, _peopleList);
this.ListAdapter = new ArrayAdapter<string>(Activity, Android.Resource.Layout.SimpleExpandableListItem1, _peopleList.ConvertAll(p => p.ToString()));
InitializeUserControlsEvents();
}
@@ -48,7 +56,7 @@ private void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
var person = _peopleList[e.Position];
var uri = Android.Net.Uri.Parse("tel:" + person.PhoneNumber);
var intent = new Intent(Intent.ActionDial, uri);
StartActivity(intent);
Oops, something went wrong.

0 comments on commit db3594f

Please sign in to comment.