C
chazon
Neues Mitglied
- 0
Hallo Leute
Jetzt habe ich doch mal eine Frage
Ich sitze gerade an einer App in welcher ich einen ViewPager verwende
also eine Activity und mehrere Fragments.
Jetzt möchte ich in den einzelnen Fragments einen Button implementieren,
welche eine neue Activity öffnen .
1. Geht so etwas überhaupt
2. Wo deklariere ich die Buttons ( alle in der Activity oder einzeln in den Fragments)
3) Wo behandele ich die Ereignisse ( SetOnClick ...)
Ich hatte einmal folgendes versucht aber ich erhalte kein Ergebnis
(Code befindet sich im Fragment)
weder kommt ein Toast noch wird die neue Seite aufgerufen.
Vielleicht könnt Ihr mir helfen
Danke und Gruß
Chazon
Jetzt habe ich doch mal eine Frage
Ich sitze gerade an einer App in welcher ich einen ViewPager verwende
also eine Activity und mehrere Fragments.
Jetzt möchte ich in den einzelnen Fragments einen Button implementieren,
welche eine neue Activity öffnen .
1. Geht so etwas überhaupt
2. Wo deklariere ich die Buttons ( alle in der Activity oder einzeln in den Fragments)
3) Wo behandele ich die Ereignisse ( SetOnClick ...)
Ich hatte einmal folgendes versucht aber ich erhalte kein Ergebnis
(Code befindet sich im Fragment)
Code:
[SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]
[LEFT]@Override[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE] [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] View onCreateView(LayoutInflater inflater, ViewGroup container,[/SIZE][/LEFT]
[SIZE=2] [LEFT]Bundle savedInstanceState) {[/LEFT]
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][/COLOR][/SIZE] [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (container == [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2])[/SIZE][/LEFT]
[SIZE=2] [LEFT]{[/LEFT]
[/SIZE] [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2];[/SIZE][/LEFT]
[SIZE=2] [LEFT]}[/LEFT]
[LEFT] [/LEFT]
[LEFT]View view = inflater.inflate(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]fpm_samstag[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], container, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]false[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]);[/SIZE][/LEFT]
[SIZE=2] [LEFT]Button btn_zug_sa = (Button) view.findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]btn_zug_sa[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE][/LEFT]
[SIZE=2] [LEFT]btn_zug_sa.setOnClickListener([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]);[/SIZE][/LEFT]
[SIZE=2] [/SIZE] [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (LinearLayout) inflater.inflate(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]fpm_samstag[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], container, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]false[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]);[/SIZE][/LEFT]
[SIZE=2] [LEFT]}[/LEFT]
[/SIZE] [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Btn_clic()[/SIZE][/LEFT]
[SIZE=2] [LEFT]{[/LEFT]
[LEFT]Toast.[I]makeText[/I](getActivity(),[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Hallo"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]).show();[/SIZE][/LEFT]
[SIZE=2] [LEFT]startActivity([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Intent([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"de.stalort.schuetzenfestzons2014.Zugweg_sa"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]));[/SIZE][/LEFT]
[SIZE=2] [LEFT]}[/LEFT]
[/SIZE] [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] onClick(View v) {[/SIZE][/LEFT]
[SIZE=2] [LEFT]Toast.[I]makeText[/I](getActivity(), [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Hallo"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]).show();[/SIZE][/LEFT]
[SIZE=2] [/SIZE] [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]switch[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](v.getId())[/SIZE][/LEFT]
[SIZE=2] [LEFT]{[/LEFT]
[/SIZE] [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]btn_zug_sa[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]:[/SIZE][/LEFT]
[SIZE=2] [LEFT]Btn_clic();[/LEFT]
[/SIZE] [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2];[/SIZE][/LEFT]
[SIZE=2] [LEFT]}[/LEFT]
}
[/SIZE]
Vielleicht könnt Ihr mir helfen
Danke und Gruß
Chazon
Zuletzt bearbeitet: