【发布时间】:2020-10-15 04:02:21
【问题描述】:
我正在尝试了解 Fragment 在 Android Studio 中的工作原理。
我在我的代码中设置了一个 LayoutInflater 但它说我的attachToRoot: false 无法解析。
这是我的代码
package com.example.rouletteapptest;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
/**
* A simple {@link Fragment} subclass.
*/
public class fragment1 extends Fragment {
TextView text,vers;
public fragment1() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_fragment1, container, attachToRoot:False);
text = view.findViewById(R.id.AndroidApp);
vers = view.findViewById(R.id.Description)
return view;
}
public void change(String txt, String txt1){
text.setText(txt);
vers.setText(txt1);
}
}
【问题讨论】:
-
删除
attachToRoot
标签: android android-studio android-layout android-fragments