0
所以我一直在嘗試使用estimote信標,並一直在學習如何使用它的教程幫助... 但最終,他們說,一個需要在列表視圖中使用哈希映射... 代碼如下: private static final Map> PLACES_BY_BEACONS;顯示信息在列表視圖(Estimote燈塔)
// TODO: replace "<major>:<minor>" strings to match your own beacons.
static {
Map<String, List<String>> placesByBeacons = new HashMap<>();
placesByBeacons.put("29098:1493", new ArrayList<String>() {{
add("Heavenly Sandwiches");
// read as: "Heavenly Sandwiches" is closest
// to the beacon with major 22504 and minor 48827
add("Green & Green Salads");
// "Green & Green Salads" is the next closest
add("Mini Panini");
// "Mini Panini" is the furthest away
}});
placesByBeacons.put("52504:13020", new ArrayList<String>() {{
add("Mini Panini");
add("Green & Green Salads");
add("Heavenly Sandwiches");
}});
PLACES_BY_BEACONS = Collections.unmodifiableMap(placesByBeacons);
}
private List<String> placesNearBeacon(Beacon beacon) {
String beaconKey = String.format("%d:%d", beacon.getMajor(), beacon.getMinor());
if (PLACES_BY_BEACONS.containsKey(beaconKey)) {
return PLACES_BY_BEACONS.get(beaconKey);
}
return Collections.emptyList();
}
private BeaconManager beaconManager;
private Region region;
ListView lv;
Button reserveButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv=(ListView)findViewById(R.id.listView);
reserveButton=(Button)findViewById(R.id.button);
beaconManager = new BeaconManager(this);
beaconManager.setRangingListener(new BeaconManager.RangingListener() {
@Override
public void onBeaconsDiscovered(Region region, List<Beacon> list) {
if (!list.isEmpty()) {
Beacon nearestBeacon = list.get(0);
List<String> places = placesNearBeacon(nearestBeacon);
// TODO: update the UI here
Log.d("Airport", "Nearest places: " + places);
}
}
});
region = new Region("ranged region",
UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D"), null, null);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Message your friends", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
所以我的問題是我怎麼顯示所有在placesByBeacons在我的UI對象(列表視圖),它是由LV在代碼中提及。
你可能在這裏尋找一個'ListView'教程...? –
這不是我正在尋找的listview教程。我試圖用一個陣列適配器來解決它,但它不起作用。所以我需要一些其他的代碼... –
你嘗試過'BaseAdapter'嗎?看看這裏的示例實現http://stackoverflow.com/questions/35495312/what-other-adapters-can-i-use-for-listview/35495669#35495669 –