On the main screen of my app there are two buttons, one to the right and the other to the left, symbolizing the previous and next months, in them I call an attempt to reload the page with the values of the previous / next month, but it does not look cool the entire screen including the actionbar being called again, I would like to somehow reload only the view / xml. I already tried invalidate (), but without success. Currently my buttons onclicks look like this:
mesProx.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
proximoMes();
Intent intent = getActivity().getIntent();
getActivity().finish();
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
getActivity().overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
}
});
mesAnt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
anteriorMes();
Intent intent = getActivity().getIntent();
getActivity().finish();
startActivity(intent);
getActivity().overridePendingTransition(R.anim.pull_in_left, R.anim.push_out_right);
}
});
And this is the app's main screen
Screencreationmethod
@OverridepublicViewonCreateView(finalLayoutInflaterinflater,finalViewGroupcontainer,finalBundlesavedInstanceState){finalViewrootView=inflater.inflate(R.layout.fragment_main,container,false);DespesaDAOdespesaDAO=newDespesaDAO(getActivity());ReceitaDAOreceitaDAO=newReceitaDAO(getActivity());GraphViewgraphView=(GraphView)rootView.findViewById(R.id.graph);TextViewdesprog=(TextView)rootView.findViewById(R.id.tvDespPrev);TextViewdespesas=(TextView)rootView.findViewById(R.id.tvsomaDesp);TextViewrecprog=(TextView)rootView.findViewById(R.id.tvRecPrev);TextViewreceitas=(TextView)rootView.findViewById(R.id.tvSomaRec);TextViewmesano=(TextView)rootView.findViewById(R.id.tvMesAno);TextViewsaldo=(TextView)rootView.findViewById(R.id.tvSaldo);TextViewsaldoprev=(TextView)rootView.findViewById(R.id.tvSaldoPrev);TextViewacumulado=(TextView)rootView.findViewById(R.id.tvAcumulado);TextViewnada=(TextView)rootView.findViewById(R.id.tvSL);ImageButtonmesAnt=(ImageButton)rootView.findViewById(R.id.btAnt);ImageButtonmesProx=(ImageButton)rootView.findViewById(R.id.btProx);Floatfrcta=receitaDAO.somaReceita(calendar);Floatfrctapg=receitaDAO.somaReceitaRecebido(calendar);Floatfdspsa=despesaDAO.somaDespesa(calendar);Floatfdspsapg=despesaDAO.somaDespesaPago(calendar);Floatsldopg=frcta-fdspsa;Floatsldo=frctapg-fdspsapg;FloatmaxValue=0.0F;FloatminValue=0.0F;Floatacmldo=receitaDAO.somaReceitaAcumulado(calendar)-despesaDAO.somaDespesaAcumulado(calendar);Floatdia1=receitaDAO.diaUmAcumulado("01", calendar) - despesaDAO.diaUmAcumulado("01", calendar);
if(dia1 > maxValue)
maxValue = dia1;
if(dia1 < minValue)
minValue = dia1;
Float dia5 = receitaDAO.diaUmAcumulado("05", calendar) - despesaDAO.diaUmAcumulado("05", calendar);
if(dia5 > maxValue)
maxValue = dia5;
if(dia5 < minValue)
minValue = dia5;
Float dia10 = receitaDAO.diaUmAcumulado("10", calendar) - despesaDAO.diaUmAcumulado("10", calendar);
if(dia10 > maxValue)
maxValue = dia10;
if(dia10 < minValue)
minValue = dia10;
Float dia15 = receitaDAO.diaUmAcumulado("15", calendar) - despesaDAO.diaUmAcumulado("15", calendar);
if(dia15 > maxValue)
maxValue = dia15;
if(dia15 < minValue)
minValue = dia15;
Float dia20 = receitaDAO.diaUmAcumulado("20", calendar) - despesaDAO.diaUmAcumulado("20", calendar);
if(dia20 > maxValue)
maxValue = dia20;
if(dia20 < minValue)
minValue = dia20;
Float dia25 = receitaDAO.diaUmAcumulado("25", calendar) - despesaDAO.diaUmAcumulado("25", calendar);
if(dia25 > maxValue)
maxValue = dia25;
if(dia25 < minValue)
minValue = dia25;
Float diaMax = receitaDAO.diaUmAcumulado(String.valueOf(calendar.getActualMaximum(Calendar.DAY_OF_MONTH)), calendar) -
despesaDAO.diaUmAcumulado(String.valueOf(calendar.getActualMaximum(Calendar.DAY_OF_MONTH)), calendar);
if(diaMax > maxValue)
maxValue = diaMax;
if(diaMax < minValue)
minValue = diaMax;
final StaticLabelsFormatter labelsFormatter = new StaticLabelsFormatter(graphView);
if(dia1 == 0 && dia5 == 0 && dia10 == 0 && dia15==0 && dia20 == 0 && dia25==0 && diaMax == 0){
nada.setVisibility(View.VISIBLE);
}else
nada.setVisibility(View.GONE);
String upperString = new SimpleDateFormat("MMMM").format(calendar.getTime()).substring(0, 1).toUpperCase() + new SimpleDateFormat("MMMM").format(calendar.getTime()).substring(1);
mesano.setText(upperString + "/" + new SimpleDateFormat("yyyy").format(calendar.getTime()));
labelsFormatter.setHorizontalLabels(new String[]{"1", "5", "10", "15", "20",
"25", String.valueOf(calendar.getActualMaximum(Calendar.DAY_OF_MONTH))});
graphView.getViewport().setYAxisBoundsManual(true);
graphView.getViewport().setMinY(minValue == 0? minValue : minValue-100 );
graphView.getViewport().setMaxY(maxValue + 100);
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(new DataPoint[]{
new DataPoint(0, Double.parseDouble(dia1.toString())),
new DataPoint(1, Double.parseDouble(dia5.toString())),
new DataPoint(2, Double.parseDouble(dia10.toString())),
new DataPoint(3, Double.parseDouble(dia15.toString())),
new DataPoint(4, Double.parseDouble(dia20.toString())),
new DataPoint(5, Double.parseDouble(dia25.toString())),
new DataPoint(6, Double.parseDouble(diaMax.toString()))
});
graphView.getGridLabelRenderer().setLabelFormatter(labelsFormatter);
series.setColor(getResources().getColor(R.color.linha_graph));
graphView.addSeries(series);
NumberFormat nf = NumberFormat.getCurrencyInstance();
desprog.setText(nf.format(Double.parseDouble(Float.toString(fdspsa))));
despesas.setText(nf.format(Double.parseDouble(Float.toString(fdspsapg))));
recprog.setText(nf.format(Double.parseDouble(Float.toString(frcta))));
receitas.setText(nf.format(Double.parseDouble(Float.toString(frctapg))));
saldo.setText(nf.format(Double.parseDouble(Float.toString(sldopg))));
saldoprev.setText(nf.format(Double.parseDouble(Float.toString(sldo))));
acumulado.setText(nf.format(Double.parseDouble(Float.toString(acmldo))));
mesProx.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
proximoMes();
Intent intent = getActivity().getIntent();
getActivity().finish();
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
getActivity().overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
}
});
mesAnt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
anteriorMes();
Intent intent = getActivity().getIntent();
getActivity().finish();
startActivity(intent);
getActivity().overridePendingTransition(R.anim.pull_in_left, R.anim.push_out_right);
}
});
return rootView;
}