我在stackoverflow上尝试了所有方法,但仍然找不到解决方案。我尝试通过设置断点进行调试, scoreView 变量的 mText 正在更新,它一直显示默认字符串startingScore
,但 UI 没有更新,我也尝试使用onUiThread
函数调用 setText。我实在想不通。有人可以帮忙吗?非常感谢(这是一个使用 metaio 的增强现实游戏)
我还检查了视图的 id 和字符串是唯一的。
ARActivity.java
public class ARActivity extends ARViewActivity {
// TextView of the score, will be updated regularly
TextView scoreView;
...
//onCreate Method in ARActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ar_view);
scoreView = (TextView) findViewById(R.id.arScoreView);
scoreView.setText("Happy day");
}
// onDrawFrame method in ARActivity.java
@Override
public void onDrawFrame() {
metaioSDK.render();
scoreView.setText("Happy day");
}
ar_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/arScoreView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="22dp"
android:layout_marginStart="28dp"
android:layout_marginTop="18dp"
android:text="@string/startingScore"
android:visibility="visible" />
字符串.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Shiny Pandas</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="how_to_play">How To Play</string>
<string name="new_game">New Game</string>
<string name="title_activity_main_menu">Shiny Pandas</string>
<string name="about_us">About Us</string>
<string name="title_activity_how_to">HowToActivity</string>
<string name="title_section1">Section 1</string>
<string name="title_section2">Section 2</string>
<string name="title_section3">Section 3</string>
<string name="title_activity_about_us">AboutUsActivity</string>
<string name="pause">Pause</string>
<string name="startingScore">Score: 0</string>
</resources>
============ 更新 ==============
我才意识到,当我点击手机上的后退按钮返回菜单时,当时的默认文本发生了变化。