A
AlexL1980
Neues Mitglied
- 0
Hallo!
Ich habe eine CustomImageView erstellt:
Ich habe eine CustomImageView erstellt:
Code:
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Landkarte [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Activity {[/SIZE]
[LEFT][SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf]/** Called when the activity is first created. */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onCreate(Bundle savedInstanceState) {[/SIZE][/LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].onCreate(savedInstanceState);[/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//setContentView(R.layout.landkarte);[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
[SIZE=2]CustomImageView myView = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] CustomImageView(getApplicationContext()); [/SIZE]
[SIZE=2]System.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]out[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2].println([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Setting the view"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); [/SIZE]
[SIZE=2]myView.invalidate(); [/SIZE]
[SIZE=2]setContentView(myView); [/SIZE]
[LEFT][SIZE=2]System.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]out[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2].println([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Calling invalidate"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); [/SIZE][/LEFT]
[LEFT][SIZE=2]}[/SIZE][/LEFT]
[SIZE=2]}[/SIZE]
Das funktioniert sehr gut. Habe eine eigene ondraw-Funktion geschrieben. Jetzt möchte ich aber auf Benutzereingaben reagieren und bei einem Klick auf einen bestimmten Bereich auf dem Bildschirm einen neuen Intent starten:
Code:
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] CustomImageView [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ImageView[/SIZE][/LEFT]
[LEFT][SIZE=2]{ [/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] CustomImageView(Context context) [/SIZE][/LEFT]
[LEFT][SIZE=2]{ [/SIZE][/LEFT]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](context); [/SIZE]
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// [/COLOR][/SIZE][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f9fbf][SIZE=2][COLOR=#7f9fbf]TODO[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f] Auto-generated constructor stub [/COLOR][/SIZE][/COLOR][/SIZE]
[LEFT][SIZE=2]setBackgroundColor(0xffffffff);[/SIZE][/LEFT]
[LEFT][SIZE=2]} [/SIZE][/LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] CustomImageView(Context context, AttributeSet attrs) [/SIZE][/LEFT]
[LEFT][SIZE=2]{ [/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](context, attrs); [/SIZE]
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// [/COLOR][/SIZE][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f9fbf][SIZE=2][COLOR=#7f9fbf]TODO[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f] Auto-generated constructor stub [/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
[SIZE=2]} [/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] CustomImageView(Context context, AttributeSet attrs, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] defStyle) [/SIZE][/LEFT]
[LEFT][SIZE=2]{ [/SIZE][/LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](context, attrs, defStyle); [/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// [/COLOR][/SIZE][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f9fbf][SIZE=2][COLOR=#7f9fbf]TODO[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f] Auto-generated constructor stub [/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
[LEFT][SIZE=2]} [/SIZE][/LEFT]
[SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]protected [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onDraw(Canvas canvas) [/SIZE][/LEFT]
[LEFT][SIZE=2]{ [/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// [/COLOR][/SIZE][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f9fbf][SIZE=2][COLOR=#7f9fbf]TODO[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f] Auto-generated method stub [/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].onDraw(canvas); [/SIZE]
[SIZE=2]....[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
[LEFT][SIZE=2][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE][/SIZE][/LEFT]
[LEFT][SIZE=2][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]boolean[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onTouchEvent(MotionEvent event) [/SIZE][/SIZE][SIZE=2][SIZE=2]{ [/SIZE][/SIZE][/LEFT]
[LEFT][SIZE=2][SIZE=2][SIZE=2]Intent intent = [/SIZE][/SIZE][/SIZE][SIZE=2][SIZE=2][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Intent([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]CustomImageView.this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2], Hauptscreen.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]); [/SIZE][/SIZE][/SIZE][SIZE=2][/LEFT]
[SIZE=2][SIZE=2][U]startActivity[/U](intent);[/SIZE]
[SIZE=2][U]finish[/U]();[/SIZE]
[LEFT]}[/LEFT]
[/SIZE][/SIZE]
Leider funktioniert das nicht. Die Meldung besagt: The constructor Intent(CustomImageView, class<Hauptscreen>) is undefinied.
Das liegt bestimmt daran, dass diese Klasse kein extends Activity sondern extends ImageView enthält... aber wie kann ich mir da helfen? Ich verstehe noch nicht ganz, wie die intents untereinander agieren können... wie komme ich aus der CustomImageView wieder raus um von der Landkarte class neue intents zu starten?
Vielen Dank!
Gruß,
Alex
Zuletzt bearbeitet: