我在计算与google方向api的距离后尝试在展开列表视图中显示该项目但是它给出了空列表,但是当点击搜索按钮时它会显示。请建议我摆脱这个问题
public List<SqliteServiceCenterListData> getAllInfo(String countryName, final String userLocationLatitude, final String userLocationLongitude) {
final List<SqliteServiceCenterListData> dataList = new ArrayList<>();
SQLiteDatabase db = this.getWritableDatabase();
String selectQuery = "SELECT * FROM service_center_info WHERE country_name=?";
final Cursor cursor = db.rawQuery(selectQuery, new String[]{countryName.trim()});
cursor.moveToFirst();
while (cursor.isAfterLast() == false) {
final SqliteServiceCenterListData sqliteServiceCenterListData = new SqliteServiceCenterListData();
sqliteServiceCenterListData.setCountryId(cursor.getString(1));
sqliteServiceCenterListData.setZoneId(cursor.getString(2));
sqliteServiceCenterListData.setCityId(cursor.getString(3));
sqliteServiceCenterListData.setServiceCenterId(cursor.getString(4));
sqliteServiceCenterListData.setCountryName(cursor.getString(5));
sqliteServiceCenterListData.setZoneName(cursor.getString(6));
sqliteServiceCenterListData.setCityName(cursor.getString(7));
sqliteServiceCenterListData.setServiceCenterName(cursor.getString(8));
sqliteServiceCenterListData.setOpeningTime(cursor.getString(9));
sqliteServiceCenterListData.setClosingTime(cursor.getString(10));
sqliteServiceCenterListData.setLocation(cursor.getString(11));
sqliteServiceCenterListData.setContact(cursor.getString(12));
sqliteServiceCenterListData.setContactPerson(cursor.getString(13));
sqliteServiceCenterListData.setLatitude(cursor.getString(14));
sqliteServiceCenterListData.setLongitude(cursor.getString(15));
if (new ConnectionManager(context).isConnectionToInternet()) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
new GetDistanceFromServer(context, String.valueOf(userLocationLatitude), String.valueOf(userLocationLongitude), sqliteServiceCenterListData.getLatitude(), sqliteServiceCenterListData.getLongitude()).getDistanceFromServer(new DistanceInfoHolder() {
@Override
public void setDistance(String distance) {
Log.e("Distance", distance);
sqliteServiceCenterListData.setDistances(distance);
dataList.add(sqliteServiceCenterListData);
}
});
return null;
}
}.execute();
} else {
dataList.add(sqliteServiceCenterListData);
}
cursor.moveToNext();
}
cursor.close();
db.close();
return dataList;
}
答案 0 :(得分:0)
将此代码放在适配器的getGroupView中
((ExpandableListView) parent).expandGroup(groupPosition);