Я создаю приложение, в котором я сталкиваюсь с ошибкой. Я хочу добавить OnclickListner на кнопку. эта кнопка находится в классе фрагмента. и из этого класса фрагмента я хочу перейти на другой класс. код ниже:
код класса фрагмента (JAVA)
public class ModeFragment extends Fragment implements TitledFragment {
private ModeViewModel viewModel;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
try {
viewModel = BackAwareApplication.getContainer().getInstance(ModeViewModel.class);
} catch (Exception e) {
e.printStackTrace();
}
View v = inflater.inflate(R.layout.mode_fragment, container, false);
Button btn_monitoring = (Button) v.findViewById(R.id.btn_belt_monitoring);
btn_monitoring.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(ModeFragment.this , BluetoothActivity.class);
startActivity(intent);
}
});
класс фрагмента XML:
<Button
android:id="@+id/btn_belt_monitoring"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Belt Monitoring"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.96" />
и ошибка:
error: no suitable constructor found for Intent(ModeFragment,Class<BluetoothActivity>)
constructor Intent.Intent(String,Uri) is not applicable
(argument mismatch; ModeFragment cannot be converted to String)
constructor Intent.Intent(Context,Class<?>) is not applicable
(argument mismatch; ModeFragment cannot be converted to Context)
Я прочитал эту ссылку, но не решил проблему