This code you posted does not have a click function, it is running all this when the OnCreateView()
is started. Try to do so:
In your class, right after the extends Cronograma
, add implements View.OnClickListener
.
And in the OnCreateView()
do this:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.solicitacoes, container, false);
Button button1 = view.findViewById(R.id.id_do_button1);
Button button2 = view.findViewById(R.id.id_do_button2);
Button button3 = view.findViewById(R.id.id_do_button3);
button1.setOnClickListener(this);
button2.setOnClickListener(this);
button3.setOnClickListener(this);
return view;
}
So to finish just create (the correct term I think is to implement) the function of OnClick
:
Obs: I gave a simplified in its function using switch
instead of if
, taking into account that you just want to catch the event of clicking the buttons on this classe
:
@Override
public void onClick(View v) {
String url = "";
switch (v.getId()) {
case R.id.button:
url = "sua url aqui";
break;
case R.id.button:
url = "sua url aqui";
break;
default: // padrão, seria igual o else aqui
url = "url padrão aqui";
break;
Intent it = new Intent(Intent.ACTION_VIEW, Uri.parse(url))...
startActivity(it);
}
}
What mistake does it make? Post the log of errors.
– ramaral
If by clicking the button the page opens then the error is not on the button.
– Bruno Romualdo
Another mistake I realized, is that even without pressing the button he enter the links, one behind the other. It’s as if these conditions had not been worth
– Carlos Diego
kkkk Now that I stopped to look no click function there
– Bruno Romualdo
All this is executed when Oncreateview() is started.
– Bruno Romualdo
I’ll show you how to do a function like that.
– Bruno Romualdo
Blz Bruno, I’m on hold
– Carlos Diego