mirror of
https://github.com/mgroves/MonodroidStockPortfolio.git
synced 2025-03-13 17:00:25 -09:00
created context menu for positions, using the .Tag of the enclosing view to store the db id
This commit is contained in:
parent
f09a6350c4
commit
182c0c8f10
2 changed files with 33 additions and 1 deletions
|
@ -169,6 +169,11 @@ namespace MonoStockPortfolio.Core.PortfolioRepositories
|
|||
{
|
||||
db.ExecSQL("CREATE TABLE " + PORTFOLIO_TABLE_NAME + " (id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT)");
|
||||
db.ExecSQL("CREATE TABLE " + POSITION_TABLE_NAME + " (id INTEGER PRIMARY KEY AUTOINCREMENT, Ticker TEXT, Shares REAL, PricePerShare REAL, ContainingPortfolioID INT)");
|
||||
|
||||
db.ExecSQL("INSERT INTO " + PORTFOLIO_TABLE_NAME + " (Name) VALUES ('Test portfolio')");
|
||||
db.ExecSQL("INSERT INTO " + POSITION_TABLE_NAME + " (Ticker, Shares, PricePerShare, ContainingPortfolioID) VALUES ('XIN', '300', '2.98', 1)");
|
||||
db.ExecSQL("INSERT INTO " + POSITION_TABLE_NAME + " (Ticker, Shares, PricePerShare, ContainingPortfolioID) VALUES ('MSFT', '300', '25.18', 1)");
|
||||
db.ExecSQL("INSERT INTO " + POSITION_TABLE_NAME + " (Ticker, Shares, PricePerShare, ContainingPortfolioID) VALUES ('AAPL', '300', '300', 1)");
|
||||
}
|
||||
|
||||
public override void OnUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
|
||||
|
|
|
@ -51,6 +51,31 @@ namespace MonoStockPortfolio.Activites
|
|||
}
|
||||
}
|
||||
|
||||
public override void OnCreateContextMenu(IContextMenu menu, View v, IContextMenuContextMenuInfo menuInfo)
|
||||
{
|
||||
base.OnCreateContextMenu(menu, v, menuInfo);
|
||||
|
||||
var info = (AdapterView.AdapterContextMenuInfo)menuInfo;
|
||||
var selectedPositionId = int.Parse(info.TargetView.Tag.ToString());
|
||||
|
||||
menu.SetHeaderTitle("Options");
|
||||
menu.Add(0, selectedPositionId, 1, "Edit");
|
||||
menu.Add(0, selectedPositionId, 2, "Delete");
|
||||
}
|
||||
|
||||
public override bool OnContextItemSelected(IMenuItem item)
|
||||
{
|
||||
if (item.Title.ToS() == "Edit")
|
||||
{
|
||||
Toast.MakeText(this, "edit: " + item.ItemId, ToastLength.Long).Show();
|
||||
}
|
||||
else if (item.Title.ToS() == "Delete")
|
||||
{
|
||||
Toast.MakeText(this, "delete: " + item.ItemId, ToastLength.Long).Show();
|
||||
}
|
||||
return base.OnContextItemSelected(item);
|
||||
}
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
var pd = new ProgressDialog(this);
|
||||
|
@ -127,7 +152,8 @@ namespace MonoStockPortfolio.Activites
|
|||
var cell = new TextView(Context);
|
||||
cell.Text = item.Items[stockDataItem];
|
||||
cell.SetWidth(columnWidth);
|
||||
row.AddView(cell, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent));
|
||||
row.Tag = item.PositionId;
|
||||
row.AddView(cell);
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
@ -136,6 +162,7 @@ namespace MonoStockPortfolio.Activites
|
|||
private void WireUpEvents()
|
||||
{
|
||||
AddPositionButton.Click += addPositionButton_Click;
|
||||
RegisterForContextMenu(QuoteListview);
|
||||
}
|
||||
|
||||
private void SetTitle()
|
||||
|
|
Loading…
Add table
Reference in a new issue