Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button ClickListener not working Fragment to Fragment #120

Open
mwapevi opened this issue Mar 28, 2021 · 0 comments
Open

Button ClickListener not working Fragment to Fragment #120

mwapevi opened this issue Mar 28, 2021 · 0 comments

Comments

@mwapevi
Copy link

mwapevi commented Mar 28, 2021

I have created the 2 fragments, fragment_contact.xml and fragment_contacts3.xml along with their activity classes, fragment_contact.xml (Contact.java) as the button to which I added a clicklistener to fragment_contacts3.xml (Contacts3.java). However, the issue is that that Button click is not working as it supposed to take me to the next fragment.

How do I resolve this issue?

The following is the Contact.xml:

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="5dp"
    android:layout_marginTop="100dp"
    android:layout_marginRight="5dp"
    android:background="@drawable/radius"
    android:orientation="vertical"
    android:weightSum="13"
    android:backgroundTint="@color/white">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_marginTop="10dp">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fontFamily="sans-serif"
            android:gravity="center"
            android:text="Enter Contact Details"
            android:textColor="@color/white"
            android:textSize="18sp"
            android:textStyle="bold" />
    </LinearLayout>
    
    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/editTextTextPersonName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:layout_margin="10dp"
        android:padding="10dp"
        android:layout_weight="2"
        android:layout_gravity="center"
        android:background="@drawable/textbox"
        android:inputType="textPersonName"
        android:hint="Enter First Name"
        android:backgroundTint="@color/offwhite"/>
    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/editTextTextPersonLName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:layout_margin="10dp"
        android:padding="10dp"
        android:layout_weight="2"
        android:layout_gravity="center"
        android:background="@drawable/textbox"
        android:inputType="textPersonName"
        android:hint="Enter First Name"
        android:backgroundTint="@color/offwhite"/>


    <RadioGroup
        android:layout_width="238dp"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <RadioButton
            android:id="@+id/radioButton7"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_weight="1"
            android:buttonTint="@color/offwhite1"
            android:drawableTint="@color/offwhite1"
            android:gravity="center"
            android:padding="10dp"
            android:text="Female"
            android:textColor="@color/offwhite1" />
        <RadioButton
            android:id="@+id/radioButton6"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_weight="1"
            android:backgroundTint="@color/offwhite1"
            android:buttonTint="@color/offwhite1"
            android:gravity="center"
            android:padding="10dp"
            android:text="Male"
            android:textColor="@color/offwhite1" />

    </RadioGroup>
    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/dob"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:layout_margin="10dp"
        android:padding="10dp"
        android:layout_weight="2"
        android:layout_gravity="center"
        android:background="@drawable/textbox"
        android:inputType="date"
        android:hint="Date of Birth:(DD/MM/YYYY)"
        android:backgroundTint="@color/offwhite"/>

    <Button
        android:id="@+id/nextbtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:text="Next"
        android:layout_gravity="center"
        android:clickable="true"
        android:background="@drawable/textbox"/>
</LinearLayout>

The following is the Contact.java along with clicklistener:

package com.example.my_survey.ui.home;

import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import com.example.my_survey.R;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import java.util.Objects;

public class Contacts extends Fragment {

private BottomNavigationView bottomNavigationView;
private ImageView back;
private RadioGroup radioGroup;
private LinearLayout linearLayout3;
private RadioButton bt1, bt2;
private Button nextBtn;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_contacts, container, false);
    bottomNavigationView = container.getRootView().findViewById(R.id.nav_view1);
    bottomNavigationView.setVisibility(View.GONE);
    nextBtn = view.findViewById(R.id.nextbtn);


    nextBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          Intent i;

          startActivity(i=new Intent(getActivity(), Contacts3.class));
        }
    });

    return view;
}

@Override
public void onDestroyView() {
    super.onDestroyView();
    bottomNavigationView.setVisibility(View.VISIBLE);
}

@Override
public void onResume() {
    super.onResume();
    Objects.requireNonNull(((AppCompatActivity) requireActivity()).getSupportActionBar()).hide();
}

@Override
public void onStop() {
    super.onStop();
    Objects.requireNonNull(((AppCompatActivity) requireActivity()).getSupportActionBar()).hide();

}

@Override
public void onDestroy() {
    super.onDestroy();
    Objects.requireNonNull(((AppCompatActivity) requireActivity()).getSupportActionBar()).show();
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant