Fehlermeldung: "Modifier 'private' not allowed here"
Dann weg mit dem 'private'!? Oder meinst du irgendwas anderes?
Ja, das wäre auch meine Lösungsidee. Was der größere Fehler war:
"....lesefenster is not an enclosing class"
Was bedeutet das? Wenn es wirklich nur an AndroidStudio liegt, wie kann ich dann dieses Problem übergehen? Hat jemand eine Idee?
Ist es ein Problem, dass beide Klassen sich in der selben Codedatei befinden? Normalerweise sollte das doch aber problemlos gehen.
Edit: Hier mal die komplette Codedatei:
|
Quellcode
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
package com.example2.myapplication;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.Toast;
public class lesefenster extends Activity {
private GestureDetector gestureDetector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
gestureDetector = new GestureDetector(new SwipeGestureDetector());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.lesefenster, menu);
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
} return super.onTouchEvent(event);
}
public void onLeftSwipe() {
}
public void onRightSwipe() {
// Do something }
}
// Private class for gestures
//Quelle: http://www.eridem.net/android-tip-010-left-and-right-swipe-gesture-events
class SwipeGestureDetector
extends GestureDetector.SimpleOnGestureListener {
// Swipe properties, you can change it to make the swipe // longer or shorter and speed private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 200;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
try {
float diffAbs = Math.abs(e1.getY() - e2.getY());
float diff = e1.getX() - e2.getX();
if (diffAbs > SWIPE_MAX_OFF_PATH)
return false;
// Left swipe
if (diff > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
lesefenster.this.onLeftSwipe();
// Right swipe
} else if (-diff > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
lesefenster.this.onRightSwipe();
} } catch (Exception e) {
Log.e("YourActivity", "Error on gestures");
} return false;
}}
|
Auch wenn man für die Klasse eine neue Codedatei erstellt, verbessert sich nichts :/