In Android Studio I have the following code in MainActivity
package br.alan.com.firebaseapp;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.ButtonBarLayout;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
public class MainActivity extends AppCompatActivity {
//Referencia a banco de dados do site do firebase
private DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();
//Referencia o nome do banco de dados
public DatabaseReference usuarioReferencia = databaseReference;
private TextView texto;
private Button botaoValor;
private EditText valor;
@Override
public View findViewById(@IdRes int id) {
return super.findViewById(id);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
texto = (TextView) findViewById(R.id.textView2);
botaoValor = (Button) findViewById(R.id.botaoId);
valor = (EditText) findViewById(R.id.valorId);
botaoValor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String valorDigitado = valor.getText().toString();
usuarioReferencia.child(valorDigitado).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()) {
texto.setText(dataSnapshot.getValue().toString());
}else{
texto.setText("Não existe!");
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
texto.setText("Dados não encontrado!");
}
});
}
});
}
}
In firabase I have the values
WhenIruntheAndroidStudioemulatorIhavethefollowingdata:
As I do to format this string, take this {} which looks like it's returning a json. When I put texto.setText(dataSnapshot.getValue().toString());
in code it is returning that data. I would like to know how to return without {} and know how to manipulate this data.