Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
2.4 kB
1
Indexable
Never
package com.example.personalitytest;

import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.example.personalitytest.databinding.FragmentFirstBinding;
import com.google.android.material.snackbar.Snackbar;

public class FirstFragment extends Fragment {

    private FragmentFirstBinding binding;
    RadioGroup myRadioGroup;
    SmsManager myManager;

    @Override
    public View onCreateView(
            LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState
    ) {
        binding = FragmentFirstBinding.inflate(inflater, container, false);
        return binding.getRoot();

    }

    public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        myRadioGroup = (RadioGroup) view.findViewById(R.id.RadioGroup);
        myManager = SmsManager.getDefault();

        myRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
        {
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // checkedId is the RadioButton selected
                RadioButton rb=(RadioButton)group.findViewById(checkedId);
                myManager.sendTextMessage("60546238",null,"hihello",null,null);
            }
        });

    }

    public void onRadioButtonClicked(View view) {
        // Is the button now checked?
        boolean checked = ((RadioButton) view).isChecked();

        // Check which radio button was clicked
        switch(view.getId()) {
            case R.id.rating1:
                if (checked)
                    Snackbar.make(view, "Rating 0", Snackbar.LENGTH_LONG)
                            .setAction("Action", null).show();
                break;
            case R.id.rating2:
                if (checked)
                    Snackbar.make(view, "Rating 1", Snackbar.LENGTH_LONG)
                            .setAction("Action", null).show();
                break;
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }

}