0
On the main screen of my app there are two buttons, an arrow to the right and another to the left symbolizing the previous and next months, in them I call an index to reload the page with the values of the previous/next month, but it doesn’t look cool the whole screen including the actionbar being called again, I would like to somehow reload only the view/xml. I have tried the invalidate() but without success. Currently my buttons onclicks are 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 main screen of the app
Method of screen creation
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
final Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_main, container, false);
DespesaDAO despesaDAO = new DespesaDAO(getActivity());
ReceitaDAO receitaDAO = new ReceitaDAO(getActivity());
GraphView graphView = (GraphView) rootView.findViewById(R.id.graph);
TextView desprog = (TextView) rootView.findViewById(R.id.tvDespPrev);
TextView despesas = (TextView) rootView.findViewById(R.id.tvsomaDesp);
TextView recprog = (TextView) rootView.findViewById(R.id.tvRecPrev);
TextView receitas = (TextView) rootView.findViewById(R.id.tvSomaRec);
TextView mesano = (TextView) rootView.findViewById(R.id.tvMesAno);
TextView saldo = (TextView) rootView.findViewById(R.id.tvSaldo);
TextView saldoprev = (TextView) rootView.findViewById(R.id.tvSaldoPrev);
TextView acumulado = (TextView) rootView.findViewById(R.id.tvAcumulado);
TextView nada = (TextView) rootView.findViewById(R.id.tvSL);
ImageButton mesAnt = (ImageButton) rootView.findViewById(R.id.btAnt);
ImageButton mesProx = (ImageButton) rootView.findViewById(R.id.btProx);
Float frcta = receitaDAO.somaReceita(calendar);
Float frctapg = receitaDAO.somaReceitaRecebido(calendar);
Float fdspsa = despesaDAO.somaDespesa(calendar);
Float fdspsapg = despesaDAO.somaDespesaPago(calendar);
Float sldopg = frcta - fdspsa;
Float sldo = frctapg - fdspsapg;
Float maxValue = 0.0F;
Float minValue = 0.0F;
Float acmldo = receitaDAO.somaReceitaAcumulado(calendar) - despesaDAO.somaDespesaAcumulado(calendar);
Float dia1 = 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;
}
Not knowing how the screen is built/updated makes it difficult to help.
– ramaral
Have you tried using as a
ViewPager
?– rsicarelli
@ramaral inserted the method
– Allan Chrystian
@sicachester as it would be this, has some example?
– Allan Chrystian