Android TextView.setText()在sony smartwatch上不工作
我试图通过单击按钮来更改sony smartwatch控件扩展上textView中的文本。但是,Android TextView.setText()在sony smartwatch上不工作,android,textview,sony,sony-smartwatch,Android,Textview,Sony,Sony Smartwatch,我试图通过单击按钮来更改sony smartwatch控件扩展上textView中的文本。但是,TextView.setText()方法似乎不起作用 这是我的ControlExtension扩展类 class SampleControlSmartWatch2 extends ControlExtension { private static TextView textView = null; SampleControlSmartWatch2(final String host
TextView.setText()
方法似乎不起作用
这是我的ControlExtension扩展类
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
}
}
LogCat中textView的记录文本按预期显示,但emulator中的文本不会更新。有人知道怎么解决吗?谢谢。对于我来说,此代码适用于:
sendText(R.id.textToBeChanged, "changed");
是的,它起作用了。您知道如何更改主机应用程序中的文本吗?您的意思是从SmartWatch应用程序触发智能手机应用程序中的控件更新?我通过发送应用已注册的意向解决了此问题。我正在尝试在smartwatch应用上触发一个按钮单击,然后在手机上更改应用中的文本。然后,你应该在smartwatch扩展中发送意向,并在手机应用中添加广播接收器。如果您需要这方面的帮助,请打开一个新问题,因为在注释中编写的代码太多。谢谢您的建议,让我先尝试一下。:)