Android:无法从onTouchEvent动态更新textView文本

Android:无法从onTouchEvent动态更新textView文本,android,touch-event,Android,Touch Event,我正在开发一个应用程序,允许用户在屏幕上拖动一个点并设置距离值。我想要的是有一半屏幕用于拖动功能,另一半带有小工具(按钮和文本视图)。为此,我创建了一个扩展SurfaceView的类,使用了位图“点”和onTouchEvent函数,并在xml文件中引用了如下视图: <test1.DragView android:id="@+id/view" android:layout_width="fill_parent" android:layout_

我正在开发一个应用程序,允许用户在屏幕上拖动一个点并设置距离值。我想要的是有一半屏幕用于拖动功能,另一半带有小工具(按钮和文本视图)。为此,我创建了一个扩展SurfaceView的类,使用了位图“点”和onTouchEvent函数,并在xml文件中引用了如下视图:

 <test1.DragView
        android:id="@+id/view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
     />
 <TextView
            android:id="@+id/textView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
  />
我无法在DragView类中使用textView。这正常吗?如果需要,我可以提供更多的解释

编辑: 使用ReubenScratton的解决方案后,我现在可以访问我的文本视图,但出现以下错误:

AndroidRuntime(672): FATAL EXCEPTION: main
AndroidRuntime(672): android.content.res.Resources$NotFoundException: String resource ID #0x109
AndroidRuntime(672):    at android.content.res.Resources.getText(Resources.java:247)
AndroidRuntime(672):    at android.widget.TextView.setText(TextView.java:3427)
AndroidRuntime(672):    at test1.DragView.onDraw(DragView.java:73)

我在回答我自己的问题,但请注意,我只是将其他人给出的解决方案组合在一起(ReubenScrattonlazeR),这样,如果其他人有同样的问题,他就会找到整个解决方案。 因此解决方案是:首先,我必须使用

 tv=(TextView) ((Activity)getContext()).findViewById(R.id.textView)
因为如果你使用

tv=(TextView)findViewById();
您使用的是
View.findViewById()
,它将只搜索子视图

您想使用
活动.findViewById()
ReubenScratton


对于我的第二个问题,当我在
setText()
函数中直接使用int时,它不起作用,但由于lazeR的评论,我注意到了它并找到了解决方案。感谢所有帮助我的人:)。

如果您能够提供调用
setText()
的代码片段和logcat输出,那将非常方便。“它会给我带来诸如NullPointerException之类的错误”-如果您不提供生成NPE的代码和异常的堆栈跟踪,您希望我们如何提供帮助?至少是LogCatplease@Guillaume你是对的。我编辑了我的问题。我注意到的一件事是,变量“x”被转换为int。tv.setText接受字符序列。哦,等等。。。代码段是否在视图派生类中?如果是,则您使用了错误的findViewById()。。。您使用的是View.findViewById(),它将只搜索子视图。您想使用Activity.findViewById()。将行更改为“tv=(TextView)((Activity)getContext()).findviewbyd(R.id.TextView);”。
 tv=(TextView) ((Activity)getContext()).findViewById(R.id.textView)
tv=(TextView)findViewById();