gpt4 book ai didi

java - Android Studio 选项卡式 Activity

转载 作者:行者123 更新时间:2023-12-02 10:20:24 24 4
gpt4 key购买 nike

我想知道一些事情,我想在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com