I'm working on my app, and came to a huge problem. I need to implement buttons in my fragments and can't find a normal solution that works. this is the code:
package com.example.konjicdiscover10;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
public class SettingsFragment extends Fragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_settings, container, false);
}
}
and XML
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
android:paddingTop="60dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="14dp"
android:background="@color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button"
android:layout_width="350sp"
android:layout_height="50sp"
android:layout_centerHorizontal="true"
android:textSize="11sp"
android:layout_marginVertical="20dp"
android:text="dark mode(in preparation)" />
<Button
android:id="@+id/button2"
android:layout_width="350sp"
android:layout_height="50sp"
android:layout_centerHorizontal="true"
android:layout_marginVertical="80dp"
android:text="Languages(in preparation)"
android:textSize="11sp"/>
</RelativeLayout>
</ScrollView>
basically what I'm looking for is that a buttons can lead to a new fragments or activities where content will be.