3
I want to put a setOnClickListener on the button that is in a Fragment, through my Activity.
Follow the codes:
Activity:
private Button mButtonCriarConta;
//
onCreate da Activity...
mButtonCriarConta = (Button) findViewById(R.id.email_criar_button);
Log.v("OnClick", "Nao Entrou no onClick");
mButtonCriarConta.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.v("OnClick", "Entrou no onClick");
Intent intent = new Intent(LoginActivity.this, DonoDoProntuarioActivity.class);
Bundle parametros = new Bundle();
String email = mEmailCriarNovo.getText().toString();
String senhaCriar = mSenhaCriarNovo.getText().toString();
parametros.putString("email", email);
parametros.putString("senha", senhaCriar);
intent.putExtras(parametros);
startActivity(intent);
}
});
Fragment where the button is located
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_criar_novo, container, false);
//resto do método
return view;}
XML of Fragment
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/email_novo_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/campoEmailNovoUsuario"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/campoSenhaNovo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:imeActionId="@+id/login"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<CheckBox
android:id="@+id/chk_mostrar_senha"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/chk_mostrar_senha" />
<!-- <FrameLayout
android:id="@+id/fragment_placeholder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></FrameLayout> -->
<TextView
android:id="@+id/texto_termos_criar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textAlignment="center" />
<Button
android:id="@+id/email_criar_button"
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:background="@drawable/botao_arredondado"
android:gravity="center_horizontal|center_vertical"
android:text="@string/acao_nova_conta"
android:textColor="@color/branco"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
When I run the program on the phone of the app stopped working and only appears the log before entering setOnClickListener, what may be occurring and how to fix?