I'm trying to learn Java and right now I have a little problem. I'm trying to get a value from a method to another:
public void Save(View v){
Contador c = new Contador();
c.nContador = "123";
c.descricao = "Teste";
c.tipoTarifa = "Tri";
c.leituras = new ArrayList<Leitura>();
Leitura l1 = new Leitura();
l1.tipoLeitura = "HP";
l1.valorLeitura = "321";
Leitura l2 = new Leitura();
l1.tipoLeitura = "HV";
l1.valorLeitura = "654";
c.leituras.add(l1);
c.leituras.add(l2);
Gson gson = new Gson();
String json = gson.toJson(c);
System.out.print(json);
}
public void Read(View v){
Toast
.makeText(this, "I want the json here", Toast.LENGTH_LONG)
.show();
}
So I have 2 buttons: one for save and one for read. When I press "Save" the method "Save" is called and it creates the string json. I want to get that same string when i click the button "Read". How can I do this?