Hallo,
nachdem ich es nun endlich geschafft habe eine 2. Activity mit einem anderen Layout zu erstellen und auch noch zwischen beiden hin und her wechlseln kann hab ich eine Frage:
Ich kann einen Button mit einem onClick Ereignis belegen.
Dies geht anscheinend auf zwei Arten.
1. Kann ich dem Button über die Properties unter Button -> On click eine funktion / Procedure zuweisen die dann aufgerufen wird.
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]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] btnGoBackClick(View v)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]Log.[I]v[/I]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Secondclass"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"btnGoBackClick"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]finish();[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
2. Ich kann per Code dem Button einen ClickHandler zuweisen:
Code:
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055]
[LEFT][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Secondclass [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Activity {[/SIZE]
[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] onCreate(Bundle savedInstanceState) {[/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 method stub[/COLOR][/SIZE][/COLOR][/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].onCreate(savedInstanceState);[/SIZE]
[SIZE=2]setContentView(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]second[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]); [/SIZE][/LEFT]
[/LEFT]
[LEFT][SIZE=2]Button btnGoBack = (Button)findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]Button01[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
[LEFT][SIZE=2]btnGoBack.setOnClickListener([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] View.OnClickListener() {[/SIZE][/LEFT]
[/LEFT]
[LEFT][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE]
[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] onClick(View v) {[/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 method stub[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2]btnGoBack_onClick();[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]});[/SIZE][/LEFT]
[/LEFT]
[LEFT][SIZE=2]}[/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] btnGoBack_onClick()[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]Log.[I]v[/I]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Secondclass"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"btnGoBack_onClick"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]finish();[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
[/LEFT]
[LEFT][SIZE=2]}[/SIZE][/LEFT]
Meine Frage ist jetzt welche der beiden Möglichkeiten die bessere/richtigere ist?
Macht man das so in Java das umständlich über "findViewById" der Button gesucht wird und dem dann ein ClickHandler zugewiesen wird?
Macht man das bei allen elementen so?
Ich frage weil ich eine Golf Scorecard erstellen will.
Die soll dann ja 18 Buttons haben

um z.B. die Strokes einzugeben.
Ach so, ich bin aus zufll daruaf gekommen das anscheinend jede Activity in dem Maniufest per Hand angelegt werden muss.
1. Warum geht das nicht automatisch und warum steht das nirgendwo bei?
Matthias