I am making an app and in a part of it the user can update the login data, it is only he enter the screen that the data is loaded and filled, automatically. The problem is that this is not really happening! The data is not coming! I already did test via url and the data appear on the web, but in the app no! Why?
Here is my code:
package com.example.gustavo.domanda;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.Volley;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.TextHttpResponseHandler;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import cz.msebera.android.httpclient.Header;
public class AtualizarDadosLoginActivity extends AppCompatActivity {
private int idusuario;
private EditText nome;
private EditText sobrenome;
private EditText email;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_atualizar_dados);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Bundle extra = getIntent().getExtras();
if(extra != null){
idusuario = extra.getInt("idusuario");
}
Toast.makeText(this, "id usuario "+idusuario, Toast.LENGTH_SHORT).show();
getDados(idusuario);
}
private void getDados(int idusuario) {
int opcao = 1; //mostrar dados usuário
RequestParams rp = new RequestParams();
AsyncHttpClient client = new AsyncHttpClient();
client.get("http://www.reservacomdomanda.com/areaAdmin/api/admin_estabelecimento/reqDataCliJson.php?opcao="+opcao+"&idusuario="+idusuario, rp, new TextHttpResponseHandler() {
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
Toast.makeText(getBaseContext(), "Problema na conexao!"+statusCode, Toast.LENGTH_LONG).show();
}
@Override
public void onSuccess(int statusCode, Header[] headers, String responseString) {
try {
JSONObject obj = new JSONObject(responseString);
String retorno = "";
Toast.makeText(AtualizarDadosLoginActivity.this, "response: "+responseString, Toast.LENGTH_SHORT).show();
if (!obj.has("erro")) {
retorno += "\n" + obj.getString("idusuario");
retorno += "\n" + obj.getString("nome");
retorno += "\n" + obj.getString("sobrenome");
retorno += "\n" + obj.getString("email");
Toast.makeText(getBaseContext(),"Dados retornados: "+retorno, Toast.LENGTH_LONG).show();
EditText nome = (EditText) findViewById(R.id.edtNome);
EditText sobrenome = (EditText) findViewById(R.id.edtSobrenome);
EditText email = (EditText) findViewById(R.id.edtEmail);
nome.setText(obj.optString("nome").toString(), TextView.BufferType.EDITABLE);
sobrenome.setText(obj.optString("sobrenome"), TextView.BufferType.EDITABLE);
email.setText(obj.optString("email"), TextView.BufferType.EDITABLE);
}
} catch (JSONException e){
}
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.gustavo.domanda.AtualizarDadosLoginActivity"
tools:showIn="@layout/activity_atualizar_dados">
<EditText
android:id="@+id/edtNome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="41dp"
android:ems="10"
android:hint="nome"
android:inputType="textPersonName"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.503" />
<EditText
android:id="@+id/edtSobrenome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="sobrenome"
android:inputType="textPersonName"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edtNome" />
<EditText
android:id="@+id/edtEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="e-mail"
android:inputType="textPersonName"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edtSobrenome" />
<Button
android:id="@+id/btnAtualizar"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:background="@drawable/borda_botao"
android:text="Atualizar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edtEmail" />
If you run this url link in your browser, you will see that there are data to be returned.