C
Cableman
Neues Mitglied
- 1
Guten Morgen,
ich würde gerne verstehen was hier läuft.
Ich hab ein kleines Progg geschrieben welches auf ein "onTouchEvent" eine Linie zeichnet. Jedesmal wenn ein neuer "onTouchEvent" dazukommt gibt es eine neue Linie mit den Koords des Events. Soweit so gut. Bleibt der Finger auf dem Display passiert nichts mehr. Es wird, auch wenn die Position eine andere ist, keine Linie gezeichnet. Erst bei nächsten abheben und neu "touchen" gibt es neue Linie. Wenn ich aber nun ein onClickListener zusätzlich zum onTouchListener hinzufüge wird bei Positionswechsel sofort eine neue Linie gezeichnet ohne dass der Touch erneut ausgeführt werden muss.
Kann mir jemand erklären warum ich ohne onClickListener nur einmal eine Linie bekomme, aber mit onClickListener jedesmal eine neue Linie bekomme bei Positionswechsel.
Hier ist der Code:
Danke schonma im vorraus
ich würde gerne verstehen was hier läuft.
Ich hab ein kleines Progg geschrieben welches auf ein "onTouchEvent" eine Linie zeichnet. Jedesmal wenn ein neuer "onTouchEvent" dazukommt gibt es eine neue Linie mit den Koords des Events. Soweit so gut. Bleibt der Finger auf dem Display passiert nichts mehr. Es wird, auch wenn die Position eine andere ist, keine Linie gezeichnet. Erst bei nächsten abheben und neu "touchen" gibt es neue Linie. Wenn ich aber nun ein onClickListener zusätzlich zum onTouchListener hinzufüge wird bei Positionswechsel sofort eine neue Linie gezeichnet ohne dass der Touch erneut ausgeführt werden muss.
Kann mir jemand erklären warum ich ohne onClickListener nur einmal eine Linie bekomme, aber mit onClickListener jedesmal eine neue Linie bekomme bei Positionswechsel.
Hier ist der Code:
Code:
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]package[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] de.drawing;
[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.app.Activity; [/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.content.Context; [/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.graphics.Canvas; [/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.graphics.Color; [/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.graphics.Paint; [/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.os.Bundle; [/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.view.MotionEvent; [/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.view.View; [/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.widget.LinearLayout;
[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] main [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Activity {
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]float[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]x[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]float[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]y[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
LinearLayout [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]layMain[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
View.OnTouchListener [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]event2[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] View.OnTouchListener() {
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]boolean[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onTouch(View v, MotionEvent event) {
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// [/COLOR][/SIZE][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f9fbf][SIZE=2][COLOR=#7f9fbf]TODO[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f] Auto-generated method stub[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]x[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = event.getX();
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]y[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = event.getY();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]false[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
}
};
View.OnClickListener [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]event[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] View.OnClickListener() {
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onClick(View v) {
}
};
[/SIZE][SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf]/** Called when the activity is first created. */[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onCreate(Bundle savedInstanceState) {
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].onCreate(savedInstanceState);
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]layMain[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] LinearLayout([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]layMain[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setOnTouchListener([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]event2[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]layMain.setOnClickListener(event);[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]layMain[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].addView([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Mens([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]));
setContentView([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]layMain[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
}
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Mens [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] View {
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Mens(Context context) {
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/B][/COLOR][/SIZE][/COLOR][/SIZE][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[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f] Auto-generated constructor stub[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]}
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]protected[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onDraw(Canvas canvas)
{
Paint p = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Paint();
p.setColor(Color.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RED[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
canvas.drawLine(15, 15, [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]x[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] , [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]y[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], p);
invalidate();
}
}
[/LEFT]
}
[/SIZE]
Danke schonma im vorraus