MonodroidStockPortfolio/MonoStockPortfolio/AddPortfolioActivity.cs

43 lines
1.4 KiB
C#
Raw Normal View History

2010-11-02 16:26:36 +00:00
using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Widget;
using MonoStockPortfolio.Core.PortfolioRepositories;
using MonoStockPortfolio.Entities;
namespace MonoStockPortfolio
{
[Activity(Label = "Add Portfolio", MainLauncher = false)]
public class AddPortfolioActivity : Activity
{
public AddPortfolioActivity(IntPtr handle) : base(handle) { }
public static string ClassName { get { return "monoStockPortfolio.AddPortfolioActivity"; } }
private IPortfolioRepository _repo;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.layout.addportfolio);
var saveButton = FindViewById<Button>(Resource.id.btnSave);
saveButton.Click += saveButton_Click;
_repo = new AndroidSqlitePortfolioRepository(this);
}
private void saveButton_Click(object sender, EventArgs e)
{
var portfolioName = FindViewById<EditText>(Resource.id.portfolioName);
_repo.SavePortfolio(new Portfolio() {Name = portfolioName.Text.ToString()});
Toast.MakeText(this, "You saved: " + portfolioName.Text, ToastLength.Short).Show();
var intent = new Intent();
SetResult(Result.Ok, intent);
Finish();
}
}
}