У меня есть файл класса, который расширяет SurfaceView и реализует SurfaceHolder.Callback, который сохраняется как myView.java
public class myView extends SurfaceView implements SurfaceHolder.Callback
Теперь я получил еще один Java-файл GlobalVar.java, похожий на этот
import android.app.Application;
class GlobalVar extends Application {
private int touchCount;
public int getCount()
{
return touchCount;
}
public void setCount(int tCount)
{
touchCount = tCount;
}
}
Внутри класса myView (myView.java) есть функция onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event) {
int pointerCount = event.getPointerCount();
}
Теперь я хочу установить глобальную переменную touchCount в pointCount.
И я попробовал вот так
@Override
public boolean onTouchEvent(MotionEvent event) {
int pointerCount = event.getPointerCount();
GlobalVar tcount = ((GlobalVar)getApplicationWindowToken());
tcount.setCount(pointerCount);
}
И это дает мне ошибку. Как я могу установить значение глобальной переменной внутри этого файла класса myView ???
Часть приложения файла манифеста
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MyViewActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<application android:name=".GlobalVar" android:icon="@drawable/icon" android:label="@string/app_name">
</application>