GuiSR Posted January 14, 2017 at 01:42 PM Report Share #601997 Posted January 14, 2017 at 01:42 PM Bom dia, Eu estou a desenvolver um aplicação para android usando o software Android Studio. A minha aplicação contém dois Fragments: Home fragment e Genres fragment. No Genres fragment, tenho quatro ImageButton que quero que abram outros Fragments quando carregados. Para inicializar os botões, eu usei o método OnClickListener, mas surgiu uma dúvida. Eu tenho uma função com o operador switch, mas eu não sei o que pôr dentro do case de cada botão. O código é este: public class GenresFragment extends Fragment implements View.OnClickListener{ public GenresFragment() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.fragment_genres, container, false); ImageButton rapBtn = (ImageButton)v.findViewById(R.id.RapButton); ImageButton popBtn = (ImageButton)v.findViewById(R.id.PopButton); ImageButton edmBtn = (ImageButton)v.findViewById(R.id.EDMButton); ImageButton rockBtn = (ImageButton)v.findViewById(R.id.RockButton); rapBtn.setOnClickListener(this); popBtn.setOnClickListener(this); edmBtn.setOnClickListener(this); rockBtn.setOnClickListener(this); return v; } @Override public void onClick(View v) { switch (v.getId()) { case R.id.RapButton: break; case R.id.PopButton: break; case R.id.EDMButton: break; case R.id.RockButton: break; } } } Podem-me ajudar? Obrigado Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted January 16, 2017 at 10:39 AM Report Share #602025 Posted January 16, 2017 at 10:39 AM https://developer.android.com/training/basics/fragments/fragment-ui.html IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now