Как создать видимую/невидимую линейную компоновку с помощью радиогруппы?

#java #xml #android-studio

Вопрос:

Проблема, когда я нажимаю на любой переключатель, он ничего не показывает. Log.d(«myTag», «Это мое сообщение»); Я попытался отладить, но заметил печать на консоли.

fragment_one.xml

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="info.androidhive.materialtabs.fragments.OneFragment"
            android:orientation="vertical">
        
        
                <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@ id/radiogroup"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginLeft="40dp">
        
                    <RadioButton android:id="@ id/eatinid"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Eatin" />
        
        
                    <RadioButton android:id="@ id/collectionid"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Collection" />
        
                    <RadioButton android:id="@ id/deliveryid"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Delivery" />
        
                    <RadioButton android:id="@ id/awaitingid"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
        
                        android:text="Awaiting" />
        
                </RadioGroup>
        
            <!--    Eatin-->
        
            <LinearLayout
                android:id="@ id/eatinliniar"
                android:visibility="gone"
                android:orientation="vertical"
                android:padding="30dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
        
                <!-- Text Label -->
        
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="5dp"
                    android:fontFamily="@font/sailec_regular"
                    android:text="Table Name / No"
                    android:layout_marginLeft="25dp" />
        
                <!--         Spinner Element -->
        
                <Spinner
                    android:id="@ id/tbl_name"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="120dp"
                    android:layout_marginRight="120dp"
                    android:hint="Select Table" />
        
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="5dp"
                    android:fontFamily="@font/sailec_regular"
                    android:text="No of People"
                    android:layout_marginLeft="25dp" />
        
                <EditText
                    android:id="@ id/no_people"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="22dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginRight="35dp"
                    android:background="@drawable/round_border"
                    android:ems="10"
                    android:inputType="text"
                    android:textColor="@color/colorPrimary"
                    android:padding="16dp" />
        
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="25dp"
                    android:fontFamily="@font/sailec_regular"
                    android:text="Customer Name"
                    android:padding="5dp" />
        
                <EditText
                    android:id="@ id/custm_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="22dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginRight="35dp"
                    android:background="@drawable/round_border"
                    android:ems="10"
                    android:inputType="text"
                    android:padding="16dp" />
        
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="25dp"
                    android:fontFamily="@font/sailec_regular"
                    android:text="Waiter"
                    android:padding="5dp" />
        
                <Spinner
                    android:id="@ id/waiter_name"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="120dp"
                    android:layout_marginRight="120dp"
                    android:hint="select table" />
        
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="5dp"
                    android:text="Order Total"
                    android:fontFamily="@font/sailec_regular"
                    android:layout_marginLeft="25dp" />
        
                <Button
                    android:id="@ id/btn1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_marginBottom="18dp"
                    android:background="@drawable/rounded_button"
                    android:fontFamily="@font/sailec_regular"
                    android:layout_marginLeft="20dp"
                    android:layout_marginRight="40dp"
                    android:layout_marginTop="32dp"
                    android:gravity="center"
                    android:padding="10dp"
                    android:textColor="#ffffff"
                    android:textSize="16dp"
                    android:textStyle="bold"
                    android:text="Send" />
        
                <Button
                    android:id="@ id/btn2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:background="@drawable/rounded_button"
                    android:fontFamily="@font/sailec_regular"
                    android:layout_marginBottom="18dp"
                    android:layout_marginLeft="20dp"
                    android:layout_marginRight="40dp"
                    android:layout_marginTop="32dp"
                    android:gravity="center"
                    android:padding="10dp"
                    android:textColor="#ffffff"
                    android:textSize="16dp"
                    android:textStyle="bold"
                    android:text="Cancel" />
        
            </LinearLayout>
            <!--Collection-->
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent">
        
                <LinearLayout
                    android:orientation="vertical"
                    android:visibility="gone"
                    android:padding="30dp"
                    android:id="@ id/collectionliniar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
        
                    <!-- Collection Label -->
        
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:text="Contact No"
                        android:fontFamily="@font/sailec_regular"
                        android:layout_marginLeft="25dp"
                        android:padding="5dp" />
        
                    <EditText
                        android:id="@ id/c_no"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="10dp"
                        android:layout_marginLeft="22dp"
                        android:layout_marginTop="5dp"
                        android:layout_marginRight="35dp"
                        android:background="@drawable/round_border"
                        android:ems="10"
                        android:padding="5dp" />
        
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:text="Customer Name"
                        android:fontFamily="@font/sailec_regular"
                        android:layout_marginLeft="25dp"
                        android:padding="5dp" />
        
        
                    <EditText
                        android:id="@ id/cs_name"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="10dp"
                        android:ems="10"
                        android:inputType="text"
                        android:padding="5dp"
                        android:layout_marginLeft="22dp"
                        android:layout_marginTop="5dp"
                        android:layout_marginRight="35dp"
                        android:background="@drawable/round_border" />
        
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:text="Customer Note(s) only for admin"
                        android:layout_marginLeft="25dp"
                        android:fontFamily="@font/sailec_regular"
                        android:padding="5dp" />
        
                    <EditText
                        android:id="@ id/c_n"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="10dp"
                        android:hint="Customer note only for view in future"
                        android:ems="10"
                        android:inputType="text"
                        android:padding="5dp"
                        android:layout_marginLeft="22dp"
                        android:layout_marginTop="5dp"
                        android:layout_marginRight="35dp"
                        android:background="@drawable/round_border" />
        
                    <Button
                        android:id="@ id/btn3"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="25dp"
                        android:layout_marginRight="40dp"
                        android:layout_marginBottom="18dp"
                        android:background="@drawable/rounded_button"
                        android:fontFamily="@font/sailec_regular"
                        android:gravity="center"
                        android:padding="10dp"
                        android:textColor="#ffffff"
                        android:textSize="16dp"
                        android:textStyle="bold"
                        android:text="Send" />
        
                    <Button
                        android:id="@ id/btn4"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="5dp"
                        android:layout_marginRight="40dp"
                        android:layout_marginBottom="18dp"
                        android:background="@drawable/rounded_button"
                        android:fontFamily="@font/sailec_regular"
                        android:gravity="center"
                        android:padding="10dp"
                        android:text="Cancel"
                        android:textColor="#ffffff"
                        android:textSize="16dp"
                        android:textStyle="bold" />
        
                </LinearLayout>
            </ScrollView>
            <!--Awaiting-->
            <LinearLayout
        
                android:orientation="vertical"
                android:padding="30dp"
                android:visibility="gone"
                android:id="@ id/awaitingliniar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
        
                <!-- Awaiting Label -->
        
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="5dp"
                    android:fontFamily="@font/sailec_regular"
                    android:layout_marginLeft="25dp"
                    android:text="Contact No"/>
        
                <EditText
                    android:id="@ id/ct_no"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/sailec_regular"
                    android:inputType="text"
                    android:padding="5dp"
                    android:layout_marginLeft="22dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginRight="35dp"
                    android:background="@drawable/round_border" />
        
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/sailec_regular"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="5dp"
                    android:layout_marginLeft="25dp"
                    android:text="Customer Name" />
        
                <EditText
                    android:id="@ id/cst_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/sailec_regular"
                    android:inputType="text"
                    android:padding="5dp"
                    android:layout_marginLeft="22dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginRight="35dp"
                    android:background="@drawable/round_border" />
        
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/sailec_regular"
                    android:text="Customer Note(s) only for admin"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="5dp"
                    android:layout_marginLeft="25dp" />
        
                <EditText
                    android:id="@ id/c_admin"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/sailec_regular"
                    android:hint="Customer note only for view in future"
                    android:ems="10"
                    android:inputType="text"
                    android:padding="5dp"
                    android:layout_marginLeft="22dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginRight="35dp"
                    android:background="@drawable/round_border" />
        
                <Button
                    android:id="@ id/btn5"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_marginLeft="20dp"
                    android:layout_marginTop="25dp"
                    android:layout_marginRight="40dp"
                    android:layout_marginBottom="18dp"
                    android:background="@drawable/rounded_button"
                    android:fontFamily="@font/sailec_regular"
                    android:gravity="center"
                    android:padding="10dp"
                    android:textColor="#ffffff"
                    android:textSize="16dp"
                    android:textStyle="bold"
                    android:text="Send" />
        
                <Button
                    android:id="@ id/btn6"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_marginLeft="20dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginRight="40dp"
                    android:layout_marginBottom="18dp"
                    android:background="@drawable/rounded_button"
                    android:fontFamily="@font/sailec_regular"
                    android:gravity="center"
                    android:padding="10dp"
                    android:textColor="#ffffff"
                    android:textSize="16dp"
                    android:textStyle="bold"
                    android:text="Cancel" />
        
            </LinearLayout>
        
            <!--Delivery-->
          
    
     
    > OneFragment.java
     
    package com.app.restaurantpos.pos.fragments;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.LinearLayout;
    import android.widget.RadioButton;
    import android.widget.RadioGroup;
    import androidx.fragment.app.Fragment;
    import com.app.restaurantpos.R;
    
    public class OneFragment extends Fragment {
        private LinearLayout eatenlinearLayout, collectionlinearLayout, deliverylinearLayout, awatinglinearLayout;
        private RadioGroup radioGroup;
        private RadioButton eatin, collection, delivery, awaiting;
        private RadioButton checkedButtonId;
    
        public OneFragment() {
            // Required empty public constructor
        }
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            View view = getView();
            if (view != null) {
                radioGroup = (view).findViewById(R.id.radiogroup);
                eatin = (view).findViewById(R.id.eatinid);
                collection = (view).findViewById(R.id.collectionid);
                delivery = (view).findViewById(R.id.deliveryid);
                awaiting = (view).findViewById(R.id.awaitingid);
                View eatinlinearlayout = (view).findViewById(R.id.eatinliniar);
                View collectionlinearlayout = (view).findViewById(R.id.collectionliniar);
                View deliverylinearlayout = (view).findViewById(R.id.deliveryliniar);
                View awatinglinearlayout = (view).findViewById(R.id.awaitingliniar);
    
                eatin.setOnClickListener(new View.OnClickListener()
                {
                    @Override
                    public void onClick(View v) {
                        Log.d("myTag", "This is my message");// I tried to debug, but Noting Printing on consol.
    
                        eatenlinearLayout.setVisibility(View.VISIBLE);
                        collectionlinearLayout.setVisibility(View.INVISIBLE);
                        deliverylinearLayout.setVisibility(View.INVISIBLE);
                        awatinglinearLayout.setVisibility(View.INVISIBLE);
                    }
                });
    
                collection.setOnClickListener(new View.OnClickListener()
                {
                    @Override
                    public void onClick(View v) {
                        Log.d("stag", "This is my message");
    
                        eatenlinearLayout.setVisibility(View.INVISIBLE);
                        collectionlinearLayout.setVisibility(View.VISIBLE);
                        deliverylinearLayout.setVisibility(View.INVISIBLE);
                        awatinglinearLayout.setVisibility(View.INVISIBLE);
                    }
                });
    
    
                delivery.setOnClickListener(new View.OnClickListener()
                {
                    @Override
                    public void onClick(View v) {
                        Log.d("dtag", "This is my message");//I tried to debug, but Noting Printing on consol.
    
                        eatenlinearLayout.setVisibility(View.INVISIBLE);
                        collectionlinearLayout.setVisibility(View.INVISIBLE);
                        deliverylinearLayout.setVisibility(View.VISIBLE);
                        awatinglinearLayout.setVisibility(View.INVISIBLE);
                    }
                });
    
                awaiting.setOnClickListener(new View.OnClickListener()
                {
                    @Override
                    public void onClick(View v) {
                        Log.d("atag", "This is my message");//I tried to debug, but Noting Printing on consol.
    
                        eatenlinearLayout.setVisibility(View.INVISIBLE);
                        collectionlinearLayout.setVisibility(View.INVISIBLE);
                        deliverylinearLayout.setVisibility(View.INVISIBLE);
                        awatinglinearLayout.setVisibility(View.VISIBLE);
                    }
                });
            }
        }
    
        @Override
        public View onCreateView (LayoutInflater inflater, ViewGroup container,
                                  Bundle savedInstanceState){
            // Inflate the layout for this fragment
    
            return inflater.inflate(R.layout.fragment_one, container, false);
        }
    }

> **Problem
When I click any radio button it doesnt show anything.
 

я хочу, чтобы, если я нажму 1-ю переключатель, то 1-я линейная компоновка будет видимой, а другие компоновки будут невидимыми
.d(«myTag», «Это мое сообщение»); Я пытался отладить, но заметил печать на консоли.**