作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道一些事情,我想在 android 上使用选项卡式 Activity 制作一个应用程序,我已经完成了所有操作,但是我有一个问题,我想将 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);
}
}
最佳答案
改变
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;
}
关于java - Android Studio 选项卡式 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54382172/
我是一名优秀的程序员,十分优秀!