gpt4 book ai didi

java - 我正在 fragment 中启动我的 Activity ,但变量变得空了?

转载 作者:行者123 更新时间:2023-11-29 02:37:10 25 4
gpt4 key购买 nike

这是 Activity 类的代码。

public class Form1Activity extends MainActivity {
private EditText factory_name,cell_no, _email:
private Spinner meter_type_spinner;
private Button form1submitbutton;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

factory_name = (EditText) findViewById(R.id.factorynameTF);
cell_no = (EditText) findViewById(R.id.cellnoTF);
_email = (EditText) findViewById(R.id.emailTF);

meter_type_spinner = (Spinner) findViewById(R.id.metertypedropdown);

form1submitbutton = (Button) findViewById((R.id.form1submitbtn));

List<String> metertype = new ArrayList<>();
metertype.add("day");
metertype.add("night");
ArrayAdapter<String> adpterMeterType = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, metertype);
adpterMeterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
meter_type_spinner.setAdapter(adpterMeterType);
}

这是我调用 Activity 的 fragment 代码。知道请告诉我我做错了什么。我应该在 fragment 中处理所有字段还是为每个 fragment 单独进行 Activity 以执行 View 的工作,例如编辑 tex、微调器等。

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.form1, container, false);
context = rootView.getContext();
Intent intent = new Intent(context, Form1Activity.class);
startActivity(intent);

return rootView;
}

最佳答案

尝试:

Intent intent = new Intent(getActivity(), Form1Activity.class);
getActivity().startActivity(intent);

代替

`Intent intent = new Intent(context, Form1Activity.class)`;
startActivity(intent);

关于java - 我正在 fragment 中启动我的 Activity ,但变量变得空了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46372262/

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