TextView.setText()无法在sony smartwatch上运行

时间:2014-04-18 18:22:29

标签: android textview sony sony-smartwatch

我试图通过单击按钮更改sony smartwatch控件扩展上的textView中的文本。但是,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的记录文本按预期显示,但模拟器中的文本未更新。有谁知道如何解决它?谢谢。

1 个答案:

答案 0 :(得分:1)

对我来说,这段代码有效:

sendText(R.id.textToBeChanged, "changed");