我想通過使用從Parse查詢中獲得的信息在我的應用程序中創建自定義infowindow。我遇到的問題是,我只能從主線程更新UI,而不是Parse查詢使用的後臺進程。從Parse查詢更新InfoWindow Google地圖Android
map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.info_window, null);
TextView titleInfoWindow = (TextView) v.findViewById(R.id.titleInfoWindow);
final TextView dateInfoWindow = (TextView) v.findViewById(R.id.dateInfoWindow);
TextView timeInfoWindow = (TextView) v.findViewById(R.id.timeInfoWindow);
TextView latitudeInfoWindow = (TextView) v.findViewById(R.id.latitudeInfoWindow);
TextView sexInfoWindow = (TextView) v.findViewById(R.id.sexInfoWindow);
TextView speciesInfoWindow = (TextView) v.findViewById(R.id.speciesInfoWindow);
titleInfoWindow.setText(marker.getTitle());
latitudeInfoWindow.setText(String.valueOf(marker.getPosition().latitude));
ParseQuery<ParseObject> query = ParseQuery.getQuery("deletingTest");
query.whereEqualTo("shark", marker.getTitle());
query.whereEqualTo("latitude", String.valueOf(marker.getPosition().latitude));
query.whereEqualTo("longitude", String.valueOf(marker.getPosition().longitude));
query.setLimit(100);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (scoreList.size() == 0) {
Log.d("MainActivity", "0");
} else {
Log.d("MainActivity", String.valueOf(scoreList.size()));
dateInfoWindow.setText("22");
}
}
});
return v;
}
});
因此,雖然dateInfoWindow是不是因爲它不是在主線程的titleInfoWindow和latitudeInfoWindow正在更新。能從數據中更新信息窗口的最佳方式是什麼?
這是我用於infoWindow佈局的XML文件。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#000000"
android:id="@+id/titleInfoWindow" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#000000"
android:id="@+id/dateInfoWindow"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#000000"
android:id="@+id/timeInfoWindow"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#000000"
android:id="@+id/latitudeInfoWindow"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#000000"
android:id="@+id/longitudeInfoWindow"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#000000"
android:id="@+id/sexInfoWindow"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#000000"
android:id="@+id/speciesInfoWindow"/>
</LinearLayout>
請嘗試在'done'方法中更新'infoWindow'信息 – bjiang
@bjiang我試圖在else子句中使用dateInfoWindow.setText(「22」);然而,這對infoWindow沒有任何作用,因爲至少我相信,這不在主線程中,因此不會更新ui。 –
您可以檢查您是否嘗試使用日誌輸出在主線程或後臺線程中設置文本 - 只需將線程'Thread.currentThread()。getName()'傳遞給日誌即可。 –