小编Mal*_*lin的帖子

在android sharedpreferences中设置<String>不会在强制关闭时保存

我试图使用androids共享偏好,我记录了所有内容,下面的代码实际上提交了字符串集.问题是当我强制关闭应用程序并再次启动时,settings.getStringSet返回一个空集.没有任何错误消息.

我曾尝试过PreferenceManager.getDefaultSharedPreferences,但这对我也不起作用.

谢谢你的时间.

public static final String PREFS_NAME = "MyPrefsFile";
private static final String FOLLOWED_ROUTES = "followedRoutes";
Run Code Online (Sandbox Code Playgroud)

然后在保存时调用:

public void onFollowClicked(View view){

SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();

Set<String> follows =  settings.getStringSet(FOLLOWED_ROUTES, new HashSet<String>());
follows.add(routeId);

editor.putStringSet(FOLLOWED_ROUTES, follows);
editor.commit();

}
Run Code Online (Sandbox Code Playgroud)

android sharedpreferences

21
推荐指数
2
解决办法
1万
查看次数

如何检查Excel中的日期单元格是否为空?

如果感觉这应该是非常容易的,但是如果不再检索单元格的值,我就不能让它工作.

首先,我有2个日期单元格:

Dim agreedDate As Date
Dim completedDate As Date
Run Code Online (Sandbox Code Playgroud)

这个工作..(但看起来很乱)

agreedDate = Worksheets("Data").Cells(Counter, 7).Value
completedDate = Worksheets("Data").Cells(Counter, 9).Value

If (IsEmpty(Worksheets("Data").Cells(Counter, 7).Value) = True) Or (IsEmpty(Worksheets("Data").Cells(Counter, 9).Value) = True) Then

[.. do stuff]
End If
Run Code Online (Sandbox Code Playgroud)

这不起作用 - 为什么不呢?!

agreedDate = Worksheets("Data").Cells(Counter, 7).Value
completedDate = Worksheets("Data").Cells(Counter, 9).Value

If (IsEmpty(agreedDate) = True) Or IsEmpty(completedDate) = True) Then

[.. do stuff]
End If
Run Code Online (Sandbox Code Playgroud)

有没有办法以干净简单的方式编写if语句?

excel vba date excel-vba is-empty

8
推荐指数
1
解决办法
2万
查看次数

防止 AutocompleteTextView 减少结果

我的应用程序中有一个,但每个项目背后的内容比显示的内容AutoCompleteTextView要多得多。DropDownMenu

\n\n

我有自己ArrayAdapterAutoCompleteTextView,当用户开始输入任何内容时, autocompleteTextView 开始减少下拉列表。这就是我想要改变的。每次用户输入一个新字母时,我\xc2\xb4m都会从 中进行新的搜索database,并希望在弹出的下拉菜单中显示所有这些内容,即我不希望autocompleteTextView减少列表,因为用户正在打字。

\n\n

所以,我的问题是,有没有办法阻止 autocompleteTextView 减少结果,或者使用我自己的下拉菜单进行编辑文本视图是否更容易?

\n\n

谢谢。

\n

android autocomplete textview autocompletetextview drop-down-menu

4
推荐指数
1
解决办法
2640
查看次数

xPath:在同级之后获取父项和第二项

我有一个巨大的xml,我需要在其中找到要支付的金额。它位于距离CellText ='amount'的单元格相距2个单元格的位置

<TableRow>
    <Cell>
       <RowNo>4</RowNo>
       <CellColNo>1</CellColNo>
       <CellText>amount</CellText>
       <CellAttribute/>
    </Cell>
    <Cell>
       <RowNo>4</RowNo>
       <CellColNo>2</CellColNo>
       <CellText/>
       <CellAttribute/>
    </Cell>
    <Cell>
       <RowNo>4</RowNo>
       <CellColNo>3</CellColNo>
       <CellText>138</CellText>
       <CellAttribute/>
    </Cell>
Run Code Online (Sandbox Code Playgroud)

这是我的代码,我在这里努力构建expressionString:

XPath xPath =  XPathFactory.newInstance().newXPath();
String exprString = "//TableRow/Cell[CellText='amount:']/following-sibling::cell[2]CellText/text()";
XPathExpression expr = xPath.compile(exprString);

    Object result = expr.evaluate(doc, XPathConstants.NODESET);
    NodeList nodes = (NodeList) result;
    for (int j = 0; j < nodes.getLength(); j++) {
        System.out.println(nodes.item(j).getNodeValue());
    }
Run Code Online (Sandbox Code Playgroud)

如何创建正确的exprString?

java xml xpath

2
推荐指数
1
解决办法
7701
查看次数