0

I wanted to know something, I want to make an application on android with Tabbed Activity, I have everything done, but I have a problem, I want to put TextViews in one of the tab and it does not let me instantiate, if I put the

match = (TextView) findViewById (R.id.match);

The program tells me:

Can not resolve method 'findViewById (int)'

How could I do it? Is there any way?

package com.example.jose.firebaseimportante;

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.EditText;
import android.widget.TextView;

public class TabbedUsuarioFutbol extends Fragment{

    public TabbedUsuarioFutbol() {}

    private TextView partido1;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.futbol_tabbed_usuario, container, false);
        return rootView;
        match = (TextView)findViewById(R.id.match);

    }

}
Yousaf
  • 27,861
  • 6
  • 44
  • 69
JoSeBu
  • 175
  • 1
  • 3
  • 10

1 Answers1

1

Change

match = (TextView)findViewById(R.id.match);

to

match = rootView.findViewById(R.id.match);

and

return rootView;

should be the last statement in your onCreateView method because any statement after a return statement is unreachable statement, i.e. it will never execute.

Your onCreateView method should look like this

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
                                                        Bundle savedInstanceState) {
  View rootView = inflater.inflate(R.layout.futbol_tabbed_usuario, container, false);
  match = rootView.findViewById(R.id.match);  
  return rootView; 
}
Yousaf
  • 27,861
  • 6
  • 44
  • 69