从 android 中的两个不同数组中获取列值的新数组
Get a new array with column values from two different arrays in android
你好我有两个数组值
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();
}
}
}
一种方法可能是声明一个 bean-like class,
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;
}
你好我有两个数组值
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();
}
}
}
一种方法可能是声明一个 bean-like class,
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;
}