i have one activity with 3 fragment using bottom navigation if i start my score_fragment inside has operation using button to textview in activity if i pause it and return with resume (draft ) Activity
public class FirstPlayedActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener {
public static int i,j;
int Wickets = 0,team_wicket = 0;
public static int Score_run = 0,team_score = 0;
public static int Over= MatchActivity.Over;
public static boolean allout = false;
public static boolean end_over = false;
public static String[][] Overs = new String[Over][20] ;
private ViewPager2 viewPager;
/**
* The pager adapter, which provides the pages to the view pager widget.
*/
private FragmentStateAdapter pagerAdapter;
View view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first_played);
BottomNavigationView bottomNavigationView = findViewById(R.id.bottomNavigationView);
bottomNavigationView.setOnNavigationItemSelectedListener(this);
bottomNavigationView.setSelectedItemId(R.id.Score);
}
Score_Fragment ScoreFragment = new Score_Fragment();
Analysis_Fragment AnalysisFragment = new Analysis_Fragment();
Summary_Fragment SummaryFragment = new Summary_Fragment();
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.Score:
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.flFragment, ScoreFragment).addToBackStack(null)
.show(ScoreFragment)
.hide(SummaryFragment)
.hide(AnalysisFragment)
.commit();
return true;
case R.id.Summary:
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.flFragment, SummaryFragment).addToBackStack(null)
.hide(ScoreFragment)
.hide(AnalysisFragment)
.show(SummaryFragment)
.commit();
return true;
case R.id.Analysis:
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.flFragment, AnalysisFragment).addToBackStack(null)
.hide(ScoreFragment)
.hide(SummaryFragment)
.show(AnalysisFragment)
.commit();
return true;
}
return false;
}
score_fragment
public class Score_Fragment extends Fragment {
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
public static int Score_run = 0,team_score = 0 ,this_over = 0;
public static double Run_rate = 0.0;
public static int i,j,k;
public static int Wickets = 0,team_wicket = 0;
public static int Over= MatchActivity.Over;
public static boolean allout = false;
public static boolean end_innings = false;
public static String[][] Overs = new String[Over][20] ;
public static boolean undoState = false;
private boolean isViewShown = false;
public Score_Fragment() {
// Required empty public constructor
}
public static Score_Fragment newInstance(String param1, String param2) {
Score_Fragment fragment = new Score_Fragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
Log.i(TAG, "onCreate: ");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View View = inflater.inflate(R.layout.fragment_score_, container, false);
TextView runs = (TextView)getActivity().findViewById(R.id.runs) ;
TextView no_of_wickets = (TextView)getActivity().findViewById(R.id.no_of_wicket) ;
TextView balls = (TextView) getActivity().findViewById(R.id.over_number);
TextView run_rate = (TextView) getActivity().findViewById(R.id.run_rate);
ImageButton wicket = (ImageButton)View.findViewById(R.id.wicket);
ImageButton dot = (ImageButton)View.findViewById(R.id.dot);
ImageButton one = (ImageButton)View.findViewById(R.id.one);
ImageButton two = (ImageButton)View.findViewById(R.id.two);
ImageButton three = (ImageButton)View.findViewById(R.id.three);
ImageButton four = (ImageButton)View.findViewById(R.id.four);
ImageButton six = (ImageButton)View.findViewById(R.id.six);
ImageButton wide = (ImageButton)View.findViewById(R.id.wide);
ImageButton wide1 = (ImageButton)View.findViewById(R.id.wide_one);
ImageButton wide2 = (ImageButton)View.findViewById(R.id.wide_two);
ImageButton wide3 = (ImageButton)View.findViewById(R.id.wide_three);
ImageButton wide4 = (ImageButton)View.findViewById(R.id.wide_four);
ImageButton noball = (ImageButton)View.findViewById(R.id.noball);
ImageButton noball_one = (ImageButton)View.findViewById(R.id.noball_one);
ImageButton noball_two = (ImageButton)View.findViewById(R.id.noball_two);
ImageButton noball_three = (ImageButton)View.findViewById(R.id.noball_three);
ImageButton noball_four = (ImageButton)View.findViewById(R.id.noball_four);
ImageButton noball_six = (ImageButton)View.findViewById(R.id.noball_six);
ImageButton legbyes_one = (ImageButton)View.findViewById(R.id.lb1);
ImageButton legbyes_two = (ImageButton)View.findViewById(R.id.lb2);
ImageButton legbyes_three = (ImageButton)View.findViewById(R.id.lb3);
ImageButton legbyes_four = (ImageButton)View.findViewById(R.id.lb4);
ImageButton byes_one = (ImageButton)View.findViewById(R.id.b1);
ImageButton byes_two = (ImageButton)View.findViewById(R.id.b2);
ImageButton byes_three = (ImageButton)View.findViewById(R.id.b3);
ImageButton byes_four = (ImageButton)View.findViewById(R.id.b4);
LinearLayout this_over_display = (LinearLayout)View.findViewById(R.id.thisover_display);
i =0;
j=0;
k = 0;
wicket.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (i == Over) {
end_innings = true;
Toast.makeText(getActivity(), " END OF THE INNINGS", Toast.LENGTH_LONG).show();
} else {
Wickets = 1;
team_wicket += 1;
if (team_wicket <= 10) {
if (team_wicket == 10) {
allout = true;
}
ImageView imageView = new ImageView(getActivity());
imageView.setImageResource(R.drawable.wicket);
Addview(imageView, 75, 75);
int disp = Integer.parseInt(no_of_wickets.getText() + "");
no_of_wickets.setText(Wickets + disp + "");
Overs[i][k] = "W";
j++;
k++;
if (j == 6) {
j = 0;
k = 0;
i++;
Run_rate = team_score/i;
this_over = 0;
balls.setText(i + "." + j + "");
} else {
balls.setText(i + "." + j + "");
}
} else {
Toast.makeText(getActivity(), " All OUT !!", Toast.LENGTH_LONG).show();
}
}
}
});
dot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (i == Over) {
end_innings = true;
Toast.makeText(getActivity(), " END OF THE INNINGS", Toast.LENGTH_LONG).show();
} else {
Score_run = 0;
team_score += 0;
this_over += 0;
ImageView imageView = new ImageView(getActivity());
imageView.setImageResource(R.drawable.dot);
Addview(imageView, 75, 75);
int disp = Integer.parseInt(runs.getText() + "");
runs.setText(Score_run + disp + "");
Overs[i][k] = "0";
k++;
j++;
if (j == 6) {
j = 0;
k = 0;
i++;
Run_rate = team_score/i;
this_over = 0;
balls.setText(i + "." + j + "");
} else {
balls.setText(i + "." + j + "");
}
}
}
});
one.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (i == Over) {
end_innings = true;
Toast.makeText(getActivity(), " END OF THE INNINGS", Toast.LENGTH_LONG).show();
} else {
Score_run = 1;
team_score += 1;
this_over += 1;
ImageView imageView = new ImageView(getActivity());
imageView.setImageResource(R.drawable.one);
Addview(imageView, 75, 75);
int disp = Integer.parseInt(runs.getText() + "");
runs.setText(Score_run + disp + "");
Overs[i][k] = "1";
k++;
j++;
if (j == 6) {
j = 0;
k = 0;
i++;
Run_rate = team_score/i;
this_over = 0;
balls.setText(i + "." + j + "");
} else {
balls.setText(i + "." + j + "");
}
}
}
});
two.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (i == Over) {
end_innings = true;
Toast.makeText(getActivity(), " END OF THE INNINGS", Toast.LENGTH_LONG).show();
} else {
Score_run = 2;
team_score += 2;
this_over += 2;
ImageView imageView = new ImageView(getActivity());
imageView.setImageResource(R.drawable.two);
Addview(imageView, 75, 75);
int disp = Integer.parseInt(runs.getText() + "");
runs.setText(Score_run + disp + "");
Overs[i][k] = "2";
k++;
j++;
if (j == 6) {
j = 0;
k = 0;
i++;
Run_rate = team_score/i;
this_over = 0;
balls.setText(i + "." + j + "");
} else {
balls.setText(i + "." + j + "");
}
}
}
});
three.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (i == Over) {
end_innings = true;
Toast.makeText(getActivity(), " END OF THE INNINGS", Toast.LENGTH_LONG).show();
} else {
Score_run = 3;
team_score += 3;
this_over += 3;
ImageView imageView = new ImageView(getActivity());
imageView.setImageResource(R.drawable.three);
Addview(imageView, 75, 75);
int disp = Integer.parseInt(runs.getText() + "");
runs.setText(Score_run + disp + "");
Overs[i][k] = "3";
k++;
j++;
if (j == 6) {
j = 0;
k = 0;
i++;
Run_rate = team_score/i;
this_over = 0;
balls.setText(i + "." + j + "");
} else {
balls.setText(i + "." + j + "");
}
}
}
});
four.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (i == Over) {
end_innings = true;
Toast.makeText(getActivity(), " END OF THE INNINGS", Toast.LENGTH_LONG).show();
} else {
Score_run = 4;
team_score += 4;
this_over += 4;
ImageView imageView = new ImageView(getActivity());
imageView.setImageResource(R.drawable.four);
Addview(imageView, 75, 75);
int disp = Integer.parseInt(runs.getText() + "");
runs.setText(Score_run + disp + "");
Overs[i][k] = "4";
k++;
j++;
if (j == 6) {
j = 0;
k = 0;
i++;
Run_rate = team_score/i;
this_over = 0;
balls.setText(i + "." + j + "");
} else {
balls.setText(i + "." + j + "");
}
}
}
});
six.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (i == Over) {
end_innings = true;
Toast.makeText(getActivity(), " END OF THE INNINGS", Toast.LENGTH_LONG).show();
} else {
Score_run = 6;
team_score += 6;
this_over += 6;
ImageView imageView = new ImageView(getActivity());
imageView.setImageResource(R.drawable.six);
Addview(imageView, 75, 75);
int disp = Integer.parseInt(runs.getText() + "");
runs.setText(Score_run + disp + "");
Overs[i][k] = "6";
k++;
j++;
if (j == 6) {
j = 0;
k = 0;
i++;
Run_rate = team_score/i;
this_over = 0;
balls.setText(i + "." + j + "");
} else {
balls.setText(i + "." + j + "");
}
}
}
});
wide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (i == Over) {
end_innings = true;
Toast.makeText(getActivity(), " END OF THE INNINGS", Toast.LENGTH_LONG).show();
} else {
Score_run = 1;
team_score += 1;
this_over += 1;
ImageView imageView = new ImageView(getActivity());
imageView.setImageResource(R.drawable.wide);
Addview(imageView, 75, 75);
int disp = Integer.parseInt(runs.getText() + "");
runs.setText(Score_run + disp + "");
balls.setText(i + "." + j + "");
Overs[i][k] = "0Wd";
k++;
}
}
});
wide1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (i == Over) {
end_innings = true;
Toast.makeText(getActivity(), " END OF THE INNINGS", Toast.LENGTH_LONG).show();
} else {
Score_run = 2;
team_score += 2;
this_over += 2;
ImageView imageView = new ImageView(getActivity());
imageView.setImageResource(R.drawable.wide1);
Addview(imageView, 75, 75);
int disp = Integer.parseInt(runs.getText() + "");
runs.setText(Score_run + disp + "");
balls.setText(i + "." + j + "");
Overs[i][k] = "1Wd";
k++;
}
}
});
wide2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (i == Over) {
end_innings = true;
Toast.makeText(getActivity(), " END OF THE INNINGS", Toast.LENGTH_LONG).show();
} else {
Score_run = 3;
team_score += 3;
this_over += 3;
ImageView imageView = new ImageView(getActivity());
imageView.setImageResource(R.drawable.wide2);
Addview(imageView, 75, 75);
int disp = Integer.parseInt(runs.getText() + "");
runs.setText(Score_run + disp + "");
balls.setText(i + "." + j + "");
Overs[i][k] = "2Wd";
k++;
}
}
});
wide3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (i == Over) {
end_innings = true;
Toast.makeText(getActivity(), " END OF THE INNINGS", Toast.LENGTH_LONG).show();
} else {
Score_run = 4;
team_score += 4;
this_over += 4;
ImageView imageView = new ImageView(getActivity());
imageView.setImageResource(R.drawable.wide3);
Addview(imageView, 75, 75);
int disp = Integer.parseInt(runs.getText() + "");
runs.setText(Score_run + disp + "");
balls.setText(i + "." + j + "");
Overs[i][k] = "3Wd";
k++;
}
}
});
return View;
}
public void Addview(ImageView imageView, int width, int height) {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height);
LinearLayout this_over_display = (LinearLayout) getView().findViewById(R.id.thisover_display);
// setting the margin in linearlayout
params.setMargins(5, 5, 5, 5);
imageView.setLayoutParams(params);
// adding the image in layout
this_over_display.addView(imageView);
getView().findViewById(R.id.ball).post(new Runnable() {
@Override
public void run() {
((HorizontalScrollView) getView().findViewById(R.id.ball)).fullScroll(View.FOCUS_RIGHT);
}
});
}
}
summary_fragment
public class Summary_Fragment extends Fragment {
int runs_T = Score_Fragment.team_score;
int wicket_T = Score_Fragment.team_wicket;
public static float Run_rate ;
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
public Summary_Fragment() {
// Required empty public constructor
}
public static Summary_Fragment newInstance(String param1, String param2) {
Summary_Fragment fragment = new Summary_Fragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public void onResume() {
super.onResume();
Log.i(TAG, "onResume: ");
}
@Override
public void onPause() {
super.onPause();
Log.i(TAG, "onPause: ");
}
@Override
public void onStop() {
super.onStop();
Log.i(TAG, "onStop: ");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view= inflater.inflate(R.layout.fragment_summary_, container, false);
return view;
}
}
how to pause my fragment to current state of fragments i need solution for this