gpt4 book ai didi

java - Java中的getView和Beacon(Estimote)问题

转载 作者:行者123 更新时间:2023-11-30 04:54:16 24 4
gpt4 key购买 nike

我的想法是从信标获取标题,然后根据该标题向我发送适当的布局。但是突然间它不会识别我的查询。像 String == String 是行不通的。

这是一个 View 的代码,如果你们需要其他东西,我会发布,或者我们可以进行 skype session 来教我这个。

@Override
public View getView(int position, View convertView, ViewGroup parent) {

ProximityContent content = nearbyContent.get(position);
String beacon = content.getTitle();

if (beacon == "one") {
if (convertView == null) {
LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
assert inflater != null;

convertView = inflater.inflate(R.layout.tester_beacon_i, parent, false);
}
} else if (beacon == "two") {
if (convertView == null) {
LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
assert inflater != null;

convertView = inflater.inflate(R.layout.tester_beacon_ii, parent, false);
}
} else if (beacon == "three") {
if (convertView == null) {
LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
assert inflater != null;

convertView = inflater.inflate(R.layout.tester_beacon_iii, parent, false);
}
} else {
if (convertView == null) {
LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
assert inflater != null;

convertView = inflater.inflate(R.layout.tester_beacon_iv, parent, false);
}
}

return convertView;
}

所以每次我的应用程序启动时,我只获得 tester_beacon_iv 布局,4 次,而不是将所有 4 个信标上的所有 4 个布局放在一起。

附言我正在使用 Estimote 信标。

最佳答案

当您在 Java 中对两个字符串使用 == 时,您实际上并不是在比较字符串本身。您将需要改用 .equals(String)。这是因为 == 实际上比较的是两个对象的引用,而不是它们的值。

string1.equals(string2) 根据字符串中的实际字符比较两个字符串。

在您的情况下,前三个信标永远不会匹配,因此您将获得布局 #4。你需要写:

if (beacon.equals("one")) {
...
}

关于java - Java中的getView和Beacon(Estimote)问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59501920/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com