我想在Android中有一个library('TTR')
library('blotter')
library("quantmod")
require(quantstrat)
from <- "2016-04-01"
to <- "2016-07-01"
SPY <- getSymbols.yahoo('SPY',
env = .GlobalEnv,
return.class = 'xts',
index.class = 'Date',
from = from,
to = to,
periodicity = "daily",
auto.assign = FALSE)
SPY <- SPY[, c(1, 2, 3, 4, 5)]
names(SPY) <- c('Open','High','Low','Close','Volume')
level <- function(ts, level) {
ts$level <- level
res <- ts$level
names(res) <- c("")
return(res)
}
rm(list = ls(.blotter), envir = .blotter)
symbols = "SPY"
currency('USD')
initDate = from
from = from
to = to
initEq = 100000
strName = "test"
stock(symbols, currency = "USD", tick_size = 0.001, multiplier = 1)
getInstrument(symbols, type = "instrument")
strategy.st <- strName
portfolio.st <- strName
account.st <- strName
rm.strat(portfolio.st)
rm.strat(strategy.st)
initPortf(portfolio.st, symbols = symbols, initDate = initDate, currency = 'USD')
initAcct(account.st, portfolios = portfolio.st, initDate = initDate, currency = 'USD', initEq = initEq)
initOrders(portfolio.st, initDate = initDate)
strategy(strategy.st, store = TRUE)
addPosLimit(portfolio.st, symbols, timestamp = initDate, maxpos = 1, minpos = -1)
# indicators
add.indicator(strategy.st, name = "level",
arguments = list(ts = quote((mktdata)), level = 208.0),
label = "LEV208")
add.indicator(strategy.st, name = "level",
arguments = list(ts = quote((mktdata)), level = 212.0),
label = "LEV212")
add.indicator(strategy.st, name = "level",
arguments = list(ts = quote((mktdata)), level = 207.0),
label = "LEV207")
# signals
add.signal(strategy.st, name = "sigCrossover",
arguments = list(columns = c("Close", "LEV208"),
relationship = "gt"),
label = "OPEN")
add.signal(strategy.st, name = "sigCrossover",
arguments = list(columns = c("Close", "LEV212"),
relationship = "gt"),
label = "CLOSE")
# rules
add.rule(strategy.st, name = "ruleSignal",
arguments = list(sigcol = "OPEN", sigval = TRUE,
orderside = "long",
ordertype = "market",
prefer = "Open",
orderqty = 1,
replace = FALSE,
osFUN = osMaxPos
),
type = "enter",
label = "LE"
)
add.rule(strategy.st, name = "ruleSignal",
arguments = list(sigcol = "CLOSE", sigval = TRUE,
orderside = "long",
ordertype = "market",
prefer = "Open",
orderqty = "all",
replace = FALSE
),
type = "exit",
label = "LX"
)
add.rule(strategy.st,
name = "ruleSignal",
arguments = list(sigcol = "OPEN",
sigval = TRUE,
replace = FALSE,
orderside = "long",
ordertype = "stoplimit",
threshold = quote(0.005),
orderqty = "all",
orderset = "ocolong"),
type = "chain",
parent = "LE",
label = "StopLossLONG",
enabled = FALSE
)
applyStrategy(strategy.st, portfolio.st)
save.strategy(strategy.st)
orderbook <- getOrderBook(portfolio.st)
orderbook
,我可以在圆框中看到以前的输入,并能够删除它。此外,我可以编写一个新输入并保存它,如下图所示。
答案 0 :(得分:0)
您可以使用嵌套视图并动态添加它们。您不必在EditText中显示标记,而是可以尝试制作包含EditText的布局并将TextViews动态添加到其中。您可以将边框设置为布局的背景。您可以在res / drawable文件夹中定义边框,并将其分配给包含标记和EditText的布局。它看起来就像你提供的图片。 border.xml可以是这样的,你可以使用params:
\([^\(]*?\)
然后你需要定义&#39;圆形框的布局,我们将它命名为layout_tag.xml,它可以是一个带有自定义背景的简单LinearLayout,即框。它应该与装饰外部布局的方式非常相似。 layout_tag.xml可能包含TextView。您还可以在TextView之后添加带有删除图标的ImageView或按钮,并将这两个视图包装在layout_tag.xml中。
然后您需要将它们动态添加到搜索字段布局中,您可以找到大量帖子来帮助,例如: Android: add a TextView to LinearLayout programatically
在上面的链接中,您可以将第一段代码块调整为layout_tag.xml。第二段代码告诉您如何将layout_tag动态添加到外部布局中,即标签的容器。
最后,只要用户提交标记,您就可以将其连接起来,还记得在删除图像/按钮上添加OnClickListener。