V
V
Valentine2018-11-14 21:09:46
Java
Valentine, 2018-11-14 21:09:46

The button on the fragment does not work, how to fix it?

There is a fragment called ChildFragment1.java. It has a button whose task is to open a new activity.

package com.example.smartnovotroitsk.Navigation.ChildFragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.example.smartnovotroitsk.Navigation.ChildActivity;
import com.example.smartnovotroitsk.R;
import com.example.smartnovotroitsk.Web.Web_Med;

/**
 * A simple {@link Fragment} subclass.
 */
public class ChildFragment1 extends Fragment {
    Button btntomed;

    public ChildFragment1() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, final ViewGroup container,
                             Bundle savedInstanceState) {
        View inflatedView = inflater.inflate(R.layout.fragment_child_fragment1, container, false);
        btntomed = (Button) inflatedView.findViewById(R.id.btntomed);
        btntomed.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.btntomed:
                        Intent intent = new Intent(getActivity(), Web_Med.class);
                        startActivity(intent);
                        break;
                    default:
                        break;
            }
        }
    }
}

I get an error after build
error: reached end of file while parsing

Also, even before this error, the button was not working (I made a couple of minor changes).

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question