私は自分のタブのビューページを持っています。私は3つのタブを持っています。最初のタブで計算を行いますが、それはまだsharedPreferencesのtinyDbに保存されています。 2番目のタブで別の計算を行い、答えをtinydbに保存します。これらの答えをボタンのクリックに保存します.3番目のタブは、これらの2つの答えに基づいて計算を行うことになっています。私は計算が完璧に動作することを知っていますが、問題はこれです。私は、アプリケーションがタブ1で計算する必要があると私はタブ2に行くと私はタブ3にonCreateViewは3つの呼び出しに取得されないので、私は戻ってくるまで更新されていないタブ3にもう一度クリックすると、onCreateViewが呼び出されます。私は0にsetOffscreenPageLimitを置くようなsomethingsを試みたが、役に立たない方法で私はこれを訂正してください。onCreateViewがタブ用に呼び出されていない
これはタブ1
@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);
}
2番目のタブ
@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();
}}
ありがとうございました。 –