我要归档的内容;我想得到一个弹出列表,其中包含BikeLocations
. 此刻,我的代码有效。它的意思是id
我的所有项目都从 0 上升到例如 5。但是,当我删除BikeLocations
, 并添加新的BikeLocations
. 这些项目的id
's 不是从 0 到例如 5,而是从 5 到例如 10。这意味着我不能用 an检索id
a的,因为这不会返回 的,而是数组的索引。BikeLocation
onClick(DialogInterface dialog, int item)
id
BikeLocation
List<BikeLocation> locations = BikeLocation.listAll(BikeLocation.class);
final ArrayList<String> arrData = new ArrayList<String>();
for (BikeLocation location : locations) {
int id = Integer.parseInt(location.getId().toString());
arrData.add((id - 1), location.getTitle());
}
if (arrData.size() != 0) {
CharSequence cs[] = arrData
.toArray(new CharSequence[arrData.size()]);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Selecteer een locatie");
builder.setItems(cs, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
/*
* Locations loc = db.getLocation((item + 1)); LatLng
* testLocation = new LatLng(Float.valueOf(loc
* .getLattitude()), Float.valueOf(loc.getLongitude()));
* googleMap.addMarker(new MarkerOptions().position(
* testLocation).title(loc.getTitle()));
*/
long longId;
int intId;
intId = item + 1;
longId = Long.valueOf(intId);
BikeLocation loc = BikeLocation.findById(
BikeLocation.class, longId);
// locatie aanmaken
LatLng addLocation = new LatLng(loc.getLatitude(), loc
.getLongitude());
/*googleMap.addMarker(new MarkerOptions().position(
addLocation).title(loc.getTitle()));*/
addMarkerToMap(loc.getLatitude(), loc.getLongitude(),loc.getTitle(), false);
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
Toast.makeText(this, "Geen items gevonden", 10).show();
}
现在,我的问题是;有什么方法可以将某种BikeLocation
id 附加到项目上?