0

I am trying to change the text in a textView on the sony smartwatch control extension by a button click. However, TextView.setText() method seems not working.

Here is my ControlExtension extended class

class SampleControlSmartWatch2 extends ControlExtension {

    private static TextView textView = null;

    SampleControlSmartWatch2(final String hostAppPackageName, final Context context,
                Handler handler) {
    //...

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View layout = inflater.inflate(R.layout.sample_control_2, null);

        textView = (TextView) layout.findViewById(R.id.textToBeChanged);
    }

    //...

   public void onObjectClick(ControlObjectClickEvent event) {
        Log.i(TAG, "Before : " + textView.getText().toString());  // It shows "original"

        textView.setText("changed");

        Log.i(TAG, "After : " + textView.getText().toString());   // It shows "changed"

        textView.invalidate();           // These two methods are added after read
        textView.requestLayout();        // through several posts but it doesn't work
   }   
}

The logged text of textView in LogCat is shown as expected but the text in the emulator does not update. Anyone know how to solve it? Thank you.

Biboo Chung
  • 121
  • 1
  • 2
  • 13

1 Answers1

1

For me this code works:

sendText(R.id.textToBeChanged, "changed");
Flat Eric
  • 7,971
  • 9
  • 36
  • 45
  • Yes, it works. Do you know how to change text that in the host application? – Biboo Chung Apr 20 '14 at 09:47
  • You mean triggering an update of a control in the app on the smartphone from your SmartWatch app? I solved this by sending an intent to which the app had registered. – Flat Eric Apr 20 '14 at 09:49
  • I am trying to trigger a button click on smartwatch app and then change the text in the app on the phone. – Biboo Chung Apr 20 '14 at 10:02
  • Then you should send an intent in the SmartWatch Extension and add a BroadcastReceiver in the Phone app. If you need help with this, please open a new question because it is too much code to write in the comments – Flat Eric Apr 20 '14 at 11:05
  • Thank you for your suggestion, let me try for a while first. :) – Biboo Chung Apr 20 '14 at 11:49