0

I tried everything on stackoverflow, but still can't find a solution. I tried to debug by setting breakpoint, the scoreView variable's mText is being updated, it keep showing the default string startingScore, but the UI is not updated, i tried to call the setText using onUiThread function as well. I can't really figure it out. Can someone help? Thank you so much (This is an augmented reality game using metaio)

I have also checked the id of the view and string are unique.

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" />

Strings.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>

============ UPDATE =============

I Just realize when I click the back button on my phone back to the menu, the default text changed at that time.

Timothy Leung
  • 1,407
  • 7
  • 22
  • 39
  • after setText, try getText and check the result. If not required, remove onDrawFrame from activity and visibility from textView. Possible explanation is a problem with visibillity tag or text color. So getText will verify if the text is set. – thepace Oct 14 '14 at 04:51
  • Try using `invalidate()` or `requestLayout()` – Piyush Kukadiya Oct 14 '14 at 04:52

2 Answers2

0

My gut here tells me that something about onDrawFrame is holding on to the wrong view. The scoreView in there might not be the actual TextView that's showing. I've seen this sort of thing happen in some weird fragmentation. It would also explain why the mText inside of scoreView does change, but I'm thinking that a new view may be getting created.

On a hunch, perhaps try:

public void onDrawFrame() {
     metaioSDK.render();
     scoreView = (TextView) findViewById(R.id.arScoreView);
     scoreView.setText("Updated Text");
}

No promises, but if that happens to do the trick, great!

Wes Winn
  • 551
  • 5
  • 15
0

mSurfaceView run on UI thread and allow you to render the stuff you want to display over UI

mSurfaceView.queueEvent(new Runnable() {

    @Override
    public void run() { 

      scoreView = (TextView) findViewById(R.id.arScoreView);
      scoreView.setText("Updated Text"); 
  }
});
Saurabh
  • 975
  • 2
  • 12
  • 27