핸들 클래스를 사용하여 TextView
의 텍스트를 업데이트하는 데 바보 같은 문제가 있습니다. Google지도에서 사용자 정의 정보 창을 설정하고 있습니다. '상태'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()
,하지만 아무것도 작동하는 것. 솔루션이 정말 분명할지 모르지만 나는 그것을 볼 수 없습니다.
미리 도움을 주셔서 감사합니다.
편집
여기 내가 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>
솔루션
나는 위의 코드에서 주석 및 *** 서명 명령을 호출하여 내 창을 새로 고쳐.
당신은 주 스레드에서 UI 요소를 업데이트해야합니다. runOnUiThread()를 시도했을 때 사용한 코드를 표시하십시오. – HelloSadness
'R.layout.my_layout'을 게시 하시겠습니까? – clownba0t
레이아웃 xml? textView라는 이름이 작동하고 있기 때문에 업데이트 메커니즘과 아무 관련이 없습니다. 아마도 매핑에 문제가있을 수 있습니다! –