gpt4 book ai didi

java - 选项卡未调用 onCreateView

转载 作者:太空宇宙 更新时间:2023-11-04 11:24:53 25 4
gpt4 key购买 nike

我的选项卡有一个viewpager。我有三个选项卡,我在第一个选项卡中进行计算,将其存储在仍然是共享首选项的tinyDb 中。我还在第二个选项卡中进行了另一个计算,并将答案存储在tinydb中,然后通过单击按钮存储这些答案,第三个选项卡应该根据这两个答案进行计算。我发现计算完美,但问题是这样的。当我完成应用程序应在选项卡一中计算的内容后,我转到选项卡二,并在转到选项卡三时输入应计算的内容,选项卡三的 onCreateView 不会被调用,因此答案不会更新,直到我返回选项卡一,然后再次单击选项卡三,然后调用 onCreateView。我已经尝试过将 setOffscreenPageLimit 设置为 0 之类的操作,但没有效果,请问我该如何纠正这个问题。

这是选项卡一的代码

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_year1__timeline, container, false);
circularProgressBar = (CircularProgressBar)rootView.findViewById(R.id.circularProgressbarTimelineYr1);
textView = (TextView)rootView.findViewById(R.id.textForPercentageTimeLineYr1);
listView = (ListView) rootView.findViewById(R.id.listForTimelineYr1);
generalArray = new ArrayList<>();
tinyDB = new TinyDB(getContext());
storedList = tinyDB.getListString("savedSubjects");
storedArray = tinyDB.getListString("savedSubjects2");
saveBtn = (Button)rootView.findViewById(R.id.btnSaveYearOneFirstSemester);


generalArray.addAll(storedList);
generalArray.addAll(storedArray);
tinyDB.putListString("generalArray", generalArray);
final ArrayList<String>generalArrayStore = tinyDB.getListString("generalArray");
arrayAdapter = new CustomListAdapterForCgpa(getActivity(), generalArray, new IOnGradeSelectedListener() {
@Override
public void onGradeSelected(String key, int value) {

try
{
int studentGatheredPoints = 0;
int totalMaximumSize = 0;


for (String course : generalArrayStore) {
int courseGradeValue = getCourseGradeValue(course);
courseLoadValue = getCourseLoadValue(course);

int sum = courseGradeValue * courseLoadValue;

studentGatheredPoints += sum;

totalMaximumSize += courseLoadValue* 5;//change to the value of total edittext
}

int percent = studentGatheredPoints * 100 / totalMaximumSize;
circularProgressBar.setProgress(percent);

DecimalFormat decimalFormat = new DecimalFormat("0.00");
double total = 100;
double multiply = percent*5.00;
finalAnswer = multiply/total;
textView.setText(decimalFormat.format(finalAnswer));

}catch (ArithmeticException ae)
{
String userName = tinyDB.getString("Username");
new SweetAlertDialog(getContext(), SweetAlertDialog.NORMAL_TYPE)
.setTitleText("Haha, "+userName + " don't be in a hurry")
.setContentText("Credit loads have to be in your courses before viewing your timeline")
.setConfirmText("OK")
.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sweetAlertDialog) {
sweetAlertDialog.dismissWithAnimation();
Intent intent = new Intent(getContext(), Splanner.class);
startActivity(intent);
}
})
.show();
}

textView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
saveBtn.setVisibility(View.VISIBLE);


}

@Override
public void afterTextChanged(Editable editable) {

}
});

saveBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
saveBtn.setVisibility(View.INVISIBLE);
tinyDB.putDouble("finalAnswerYr1FirstSemester",finalAnswer);
}
});





}
});

listView.setAdapter(arrayAdapter);
arrayAdapter.notifyDataSetChanged();

return rootView;
}

private int getCourseGradeValue(String courseName) {
String key = courseName + "_selectedValue";
return tinyDB.getInt(key);
}

private int getCourseLoadValue(String courseName) {
String key = courseName + "_selectedCourseLootValue";

return tinyDB.getInt(key);
}

第二个选项卡

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_year2__timeline_second_semester, container, false);

circularProgressBar = (CircularProgressBar)rootView.findViewById(R.id.circularProgressbarTimelineYr2_2);
textView = (TextView)rootView.findViewById(R.id.textForPercentageTimeLineYr2_2);
listView = (ListView)rootView.findViewById(R.id.listForTimelineYr2_2);
tinyDB = new TinyDB(getContext());
saveBtn = (Button)rootView.findViewById(R.id.btnSaveYearTwoSecondSemesterTimeline);

storedList = tinyDB.getListString("storedList2ndYr2");
arrayAdapter = new CustomListAdapterForCgpa(getActivity(), storedList, new IOnGradeSelectedListener() {
@Override
public void onGradeSelected(String key, int value) {

try {
int studentGatheredPoints = 0;
int totalMaximumSize = 0;


for (String course : storedList) {
int courseGradeValue = getCourseGradeValue(course);
courseLoadValue = getCourseLoadValue(course);

int sum = courseGradeValue * courseLoadValue;

studentGatheredPoints += sum;

totalMaximumSize += courseLoadValue* 5;//change to the value of total edittext
}

int percent = studentGatheredPoints * 100 / totalMaximumSize;
circularProgressBar.setProgress(percent);

DecimalFormat decimalFormat = new DecimalFormat("0.00");
double total = 100;
double multiply = percent*5.00;
finalAnswer = multiply/total;
textView.setText(decimalFormat.format(finalAnswer));

}catch (ArithmeticException ae)
{
String userName = tinyDB.getString("Username");
new SweetAlertDialog(getContext(), SweetAlertDialog.NORMAL_TYPE)
.setTitleText("Haha, "+userName + " don't be in a hurry")
.setContentText("Credit loads have to be in your courses before viewing your timeline")
.setConfirmText("OK")
.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sweetAlertDialog) {
sweetAlertDialog.dismissWithAnimation();
Intent intent = new Intent(getContext(), Splanner.class);
startActivity(intent);
}
})
.show();
}


}
});

textView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
saveBtn.setVisibility(View.VISIBLE);
}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
saveBtn.setVisibility(View.VISIBLE);

}

@Override
public void afterTextChanged(Editable editable) {

}
});

saveBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
saveBtn.setVisibility(View.INVISIBLE);
String getFinalAnswer = textView.getText().toString();
double saveFinalAnswer = Double.parseDouble(getFinalAnswer);
tinyDB.putDouble("finalAnswerYr2SecondSemester",saveFinalAnswer);
}
});
listView.setAdapter(arrayAdapter);
arrayAdapter.notifyDataSetChanged();


return rootView;
}

private int getCourseGradeValue(String courseName) {
String key = courseName + "_selectedValue";
return tinyDB.getInt(key);
}

private int getCourseLoadValue(String courseName) {
String key = courseName + "_selectedCourseLootValue";

return tinyDB.getInt(key);
}

@Override
public void onResume() {
super.onResume();
}

}

第三个

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_year2__final_timeline, container, false);
circularProgressBar = (CircularProgressBar)rootView.findViewById(R.id.circularProgressbarFinalTimelineYr2);
textView = (TextView)rootView.findViewById(R.id.textForPercentageFinalTimelineYr2);
tinyDB = new TinyDB(getContext());

double yearOneFinalGpFirstSemester = tinyDB.getDouble("finalAnswerYr2FirstSemester", 0.00);
double yearOneFinalGpSecondSemester = tinyDB.getDouble("finalAnswerYr2SecondSemester", 0.00);
double finalGp = yearOneFinalGpFirstSemester+yearOneFinalGpSecondSemester;
double finalGpFinal = finalGp/2;
double val = finalGpFinal;
val = val*100;
val = (double)((int) val);
val = val /100;
textView.setText(String.valueOf(val));

int total = 5;
int change = (int) finalGpFinal;
int multiply = 100*change;
int divide = multiply/total;
circularProgressBar.setProgress(divide);

tinyDB.putDouble("FinalGpYear2", finalGpFinal);
System.out.println(yearOneFinalGpFirstSemester);


return rootView;
}

@Override
public void onResume() {
super.onResume();

}}

最佳答案

最好在 Activity 中使用页面更改监听器并在页面更改时更新 UI 内容。

        viewPager.setAdapter(fragmentPagerAdapter);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

}

@Override
public void onPageSelected(int position) {
//Get current fragment and update UI
BaseFragment fragment= (BaseFragment) fragmentPagerAdapter.getItem(position);
//assumes updateUI ,a method in BaseFragment is overriden in Fragment implementation to update UI.You can place your logic here.
fragment.updateUI();
}

@Override
public void onPageScrollStateChanged(int state) {

}
});

关于java - 选项卡未调用 onCreateView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44486707/

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