0

我想知道一些事情,我想用 Tabbed Activity 在 android 上创建一个应用程序,我已经完成了所有工作,但是我有一个问题,我想将 TextViews 放在其中一个选项卡中,如果我放了它,它不会让我实例化这

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

程序告诉我:

Can not resolve method 'findViewById (int)'

我怎么能做到?有什么办法吗?

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);

    }

}
4

1 回答 1

1

改变

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

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

return rootView;

应该是您onCreateView方法中的最后一条语句,因为语句之后的任何return语句都是无法访问的语句,即它永远不会执行。

你的onCreateView方法应该是这样的

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; 
}
于 2019-01-26T19:58:23.043 回答