我是Android的开端。 我在我的项目中有一个小问题,我想保存我的数据解析到本地数据,但我不知道该怎么办: 我从BUS_STOP解析数据到我的BusStop arraylist。 我在我的应用程序中添加了Parse.enableLocalDatastore(getApplicationContext());
。 这是我的代码下载数据到busstops:如何将数据从解析保存到本地数据
busStops = new ArrayList<>();
try {
ParseQuery<ParseObject> query = new ParseQuery<>("BUS_STOP");
query.orderByAscending("stop_id");
query.setLimit(2000);
listA = query.find();
for (ParseObject mBusStop : listA) {
BusStop newBusStop = new BusStop();
newBusStop.setName((String) mBusStop.get("name"));
newBusStop.setStreet((String) mBusStop.get("street"));
newBusStop.setStyle((String) mBusStop.get("Type"));
newBusStop.setNext_id((int) mBusStop.get("next_id"));
newBusStop.setBus_id((int) mBusStop.get("bus_id"));
newBusStop.setStop_id((int) mBusStop.get("stop_id"));
double x, y;
x = (double) mBusStop.get("coor_x");
y = (double) mBusStop.get("coor_y");
LatLng a = new LatLng(x, y);
newBusStop.setLatLngBus(a);
busStops.add(newBusStop);
}
} catch (com.parse.ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
,这是我班巴士站就
@ParseClassName("BUS_STOP")
public class BusStop extends ParseObject{
String name;
String street;
String style;
LatLng latLngBus;
int bus_id;
int next_id;
int stop_id;
public String getPName(){
return getString("name");
}
public void setPName(String name) {
put("name", name);
}
public String getPStreet(){
return getString("street");
}
public void setPStreet(String street) {
put("street", street);
}
public String getPStyle(){
return getString("Type");
}
public void setPStyle(String type) {
put("Type", type);
}
public double getMCoor_x(){
return getDouble("coor_x");
}
public void setMCoor_x(double coor_x) {
put("coor_x", coor_x);
}
public double getMCoor_y(){
return getDouble("coor_y");
}
public void setMCoor_y(double coor_y) {
put("coor_y", coor_y);
}
public int getMBus_id(){
return getInt("bus_id");
}
public void setMCoor_y(int bus_id) {
put("bus_id", bus_id);
}
public int getMNext_id(){
return getInt("next_id");
}
public void setMNext_id(int next_id) {
put("next_id", next_id);
}
public int getMStop_id(){
return getInt("stop_id");
}
public void setMStop_id(int stop_id) {
put("stop_id", stop_id);
}
public int getStop_id() {
return stop_id;
}
public void setStop_id(int stop_id) {
this.stop_id = stop_id;
}
public int getNext_id() {
return next_id;
}
public void setNext_id(int next_id) {
this.next_id = next_id;
}
public int getBus_id() {
return bus_id;
}
public void setBus_id(int bus_id) {
this.bus_id = bus_id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
public LatLng getLatLngBus() {
return latLngBus;
}
public void setLatLngBus(LatLng latLngBus) {
this.latLngBus = latLngBus;
}
}
如果我的方法是不错的方法,告诉我伟大的方式,请!
等等,你的代码是否工作? – Mauker
是啊它工作,但只加载数据在线...当我打开我的应用程序延迟2s的加载数据 –
你将不得不加载数据在后台线程,使用'服务','AsyncTask',工人'线程'或类似的东西。 – Mauker