My idea is to get the title from a beacon and based on that title send me an appropriate Layout. But suddenly it wont recognize my inquiry. Like String == String won't work.
Here is the code of a View, if you guys need something else I will post or we can make a skype session just to teach me this one.
@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;
}
So every time my app starts, I get only tester_beacon_iv
layout, 4 times instead of getting all 4 layouts on all 4 beacons together.
P.S. I am using Estimote beacons.
When you use ==
on two strings in Java, you're not actually comparing the strings themselves. You will need to use .equals(String)
instead. This is because ==
actually compares the two objects' references, not their values.
string1.equals(string2)
compares the two strings based on the actual characters in the strings.
In your case, the first three beacons will never match, so you'll aways get layout #4. You'll need to write:
if (beacon.equals("one")) {
...
}