Android Google Glass:TextView setText未在活动中工作
我正在创建一个Android Google Glass:TextView setText未在活动中工作,android,textview,google-glass,settext,Android,Textview,Google Glass,Settext,我正在创建一个浸入式类型的玻璃应用程序。我试图在活动中动态更改文本视图,但当我转到该活动时,程序就崩溃了。我不喜欢使用卡,因为它是一个沉浸式程序 知道如何让TextView.setText在常规活动中工作吗 谢谢 创建方法的活动 TextView tvTest = (TextView)findViewById(R.id.testText); @Override protected void onCreate(Bundle savedInstanceState) { super.onCr
浸入式
类型的玻璃应用程序。我试图在活动
中动态更改文本视图,但当我转到该活动时,程序就崩溃了。我不喜欢使用卡
,因为它是一个沉浸式程序
知道如何让TextView.setText
在常规活动中工作吗
谢谢
创建方法的活动
TextView tvTest = (TextView)findViewById(R.id.testText);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_checklist);
mGestureDetector = createGestureDetector(this);
readJson();
tvTest.setText("testing testing");
}
活动XML
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="40px"
tools:context=".NewChecklistActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center_horizontal"
android:text="@string/newChecklist"
android:textSize="50px"
android:textStyle="bold" />
<TextView
android:id="@+id/testText"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
将其移动到setContentView之后的onCreate中:
TextView tvTest = (TextView)findViewById(R.id.testText);
findViewByID()引用由setContentView()扩展的布局。因此,如果您事先使用它,就会返回null,因此在tvTest上调用方法时会出现null指针异常。您能发布一些代码吗?膨胀版面并从中获取
TextView
小部件的方式应该与在任何其他Android设备上的方式没有任何区别,因此相同的技术应该适用于此。@TonyAllevato添加的代码。这种方法通常适用于我使用过的任何Android程序,我很困惑为什么它不适用于Glass。