Newer
Older
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.example.mampfmobil.ui.customer.CustomerLogonFragment;
import com.example.mampfmobil.ui.customer.CustomerRegisterFragment;
import com.example.mampfmobil.ui.deliverer.DelivererLogonFragment;
import com.example.mampfmobil.ui.deliverer.DelivererRegisterFragment;
import com.example.mampfmobil.ui.supplier.SupplierLogonFragment;
import com.example.mampfmobil.ui.supplier.SupplierRegisterFragment;
public class DecideFragment extends Fragment {
private DecideViewModel mViewModel;
public static DecideFragment newInstance() {
return new DecideFragment();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_decide, container, false);
ImageButton deButton = rootView.findViewById(R.id.imageView);
ImageButton enButton = rootView.findViewById(R.id.imageView2);
deButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setLocale("de"); // Aufruf der Funktion zum Ändern der Sprache auf Deutsch
}
});
enButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setLocale("en"); // Aufruf der Funktion zum Ändern der Sprache auf Englisch
}
});
Button button = rootView.findViewById(R.id.CustomerButton);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fragmentManager = requireActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container, new CustomerLogonFragment());
fragmentTransaction.addToBackStack(null); // Fügt den Fragment-Wechsel zur Back-Stack hinzu
fragmentTransaction.commit();
Button button2 = rootView.findViewById(R.id.SupplierButton);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fragmentManager = requireActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container, new SupplierLogonFragment());
fragmentTransaction.addToBackStack(null); // Fügt den Fragment-Wechsel zur Back-Stack hinzu
fragmentTransaction.commit();
Button button3 = rootView.findViewById(R.id.DelivererButton);
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fragmentManager = requireActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container, new DelivererLogonFragment());
fragmentTransaction.addToBackStack(null); // Fügt den Fragment-Wechsel zur Back-Stack hinzu
fragmentTransaction.commit();
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mViewModel = new ViewModelProvider(this).get(DecideViewModel.class);
// TODO: Use the ViewModel
}
private void setLocale(String languageCode) {
Locale locale = new Locale(languageCode);
Resources resources = getResources();
Configuration configuration = resources.getConfiguration();
configuration.setLocale(locale);
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
// Hier müssen Sie den Fragments-Wechsel aktualisieren, um sicherzustellen,
// dass die Ansichten und Texte entsprechend der geänderten Sprache aktualisiert werden
FragmentManager fragmentManager = requireActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container, new DecideFragment());
fragmentTransaction.commit();
}