嗨我有两个数组值
loncountries[index] = [80.2116001, 80.173399]
latcountries[index] = [13.042699, 13.0409047]
现在我希望他们使用像
这样的新数组loncountries[index] = [13.042699,80.2116001]
latcountries[index] = [13.0409047,80.173399]
将第一列作为新数组。此外,我从Sqlite数据库中获取它并附加下面的代码。是否可以在从db中获取时执行此操作。
String[] latcountries;
String[] loncountries;
if (cJoin != null) {
int countJoin = cJoin.getCount();
if (countJoin > 0) {
latcountries = new String[countJoin];
loncountries = new String[countJoin];
int index = 0;
cJoin.moveToFirst();
while (!cJoin.isAfterLast()) {
loncountries[index] = cJoin.getString(0);
latcountries[index] = cJoin.getString(1);
index++;
cJoin.moveToNext();
}
}
}
答案 0 :(得分:1)
一种方法可能是声明一个类似bean的类,
public class Position {
public String mLat;
public String mLon;
}
然后声明一个位置数组:
Position[] latLon = new Position[countJoin];
每次迭代
while (!cJoin.isAfterLast()) {
Position p = new Position();
p.mLat = cJoin.getString(1);
p.mLon = cJoin.getString(0);
latLon[index++] = p;
}