ハンドラークラスを使用してTextView
のテキストを更新するのは愚かな問題があります。私はGoogle MapsでカスタムInfoウィンドウを設定しています。 「状態」TextView
だけでその内容を更新し、画面上で視覚的に更新されていない状態TextViewが更新されない
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(final Marker marker) {
//setting marker as final***
View v = getLayoutInflater().inflate(R.layout.my_layout, null);
TextView name = (TextView) v.findViewById(R.id.name);
final TextView status = (TextView) v.findViewById(R.id.status);
for(MyItem mi : myItems){
if(mi.getName().equals(marker.getTitle())){
name.setText(mi.getName()); //This one updates normaly
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//this one sets the text, but doesnt update on UI
status.setText("Text");
//Here I call my update text function
updateTv(status, "Text");
//Refreshing the window***
marker.showInfoWindow();
}
}, 5000);
break;
}
}
return v;
}
});
}
TextView
「名前」は、正常に更新されます。私はrunOnUiThread()
を無効にしようとしましたが、何も動作していないようです。解決策は本当に明白かもしれないが、私はそれを見ない。
ご協力いただきありがとうございます。
EDIT
は、ここで私はrunOnUiThreadを試みた方法です()。
public void updateTv(final TextView tv, final String s){
runOnUiThread(new Runnable() {
@Override
public void run() {
tv.setText(s);
tv.invalidate();
}
});
}
マイ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="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/name"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:padding="10dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="..."
android:id="@+id/status"
android:gravity="center_horizontal"/>
</LinearLayout>
SOLUTION
私は上記のコードで***とコメントして署名したコマンドを呼び出すことで、私のウィンドウをリフレッシュします。
あなたは、メインスレッド上のUI要素を更新する必要があります。 runOnUiThread()を試したときに使用したコードを表示します。 – HelloSadness
'R.layout.my_layout'を投稿してもよろしいですか? – clownba0t
レイアウトxml? textViewという名前が動作しているので、おそらく更新メカニズムとは関係がありません。おそらくマッピングに問題があります。 –