文本视图未更新

ten*_*a11 5 java android google-maps textview

我在TextView使用处理程序类更新文本时遇到了一个愚蠢的问题。我正在 Google 地图中设置自定义信息窗口。

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;
            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

TextView“名称”正在正常更新,而“状态”TextView仅更新其内容,而不会在屏幕上直观地更新。我试过使 , 无效,runOnUiThread()但似乎没有任何效果。我知道解决方案可能非常明显,但我没有看到。

提前谢谢你的帮助!

编辑

这是我如何尝试 runOnUiThread()。

public void updateTv(final TextView tv, final String s){

        runOnUiThread(new Runnable() {
            @Override
            public void run() {

                tv.setText(s);

                tv.invalidate();

            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

我的 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>
Run Code Online (Sandbox Code Playgroud)

解决方案

我通过调用上面代码中用 *** 注释和签名的命令来刷新我的窗口。我要感谢“clownba0t”

Ahm*_*nie 1

因此,您尝试在视图返回后更新该视图,getInfoContents()但这将不起作用,因为它不是实时视图,请参阅

可能有效的方法是调用:

status.invalidate();
Run Code Online (Sandbox Code Playgroud)