Skip to content

Instantly share code, notes, and snippets.

@nikunjparadva
Last active May 27, 2019 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikunjparadva/48b96d0aad034f2349c9c6af3783dc8e to your computer and use it in GitHub Desktop.
Save nikunjparadva/48b96d0aad034f2349c9c6af3783dc8e to your computer and use it in GitHub Desktop.
package paradva.nikss.test;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.GET;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fetch_information();
}
public static String Base_URL ;
public static Retrofit retrofit;
public static Retrofit getApiClient()
{
if (retrofit == null)
{
Base_URL ="https://xenzet.com/GameCheat/";
retrofit = new Retrofit.Builder().baseUrl(Base_URL)
.addConverterFactory(GsonConverterFactory.create()).build();
}
return retrofit;
}
public interface Api {
@GET("viewgamesjson.php")
Call<List<Games>> GetGames();
}
public void fetch_information() {
Api api = getApiClient().create(Api.class);
Call<List<Games>> call = api.GetGames();
call.enqueue(new Callback<List<Games>>() {
@Override
public void onResponse(Call<List<Games>> call, Response<List<Games>> response) {
if(response.isSuccessful()) {
Log.e("onResponse", "onResponse: "+response.body() );
}
}
@Override
public void onFailure(Call<List<Games>> call, Throwable t) {
Toast.makeText(getApplicationContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
@arsalanjibran
Copy link

arsalanjibran commented May 27, 2019

my response was this onResponse: [com.example.quizgames.Games@75ee120, com.example.quizgames.Games@abdcad9, com.example.quizgames.Games@373ac9e, com.example.quizgames.Games@70cd37f, com.example.quizgames.Games@c20ef4c, com.example.quizgames.Games@3b73b95, com.example.quizgames.Games@369f4aa]

what this suppose to mean

@arsalanjibran
Copy link

i applied your code from here in my app and this was response i got.

@nikunjparadva
Copy link
Author

yes that was responce in object mode, for converting in String formate

add this one in Games pojo

@Override public String toString() { return "Games{" + "gameid='" + gameid + '\'' + ", gameIcon='" + gameIcon + '\'' + ", gamesName='" + gamesName + '\'' + '}'; }

@nikunjparadva
Copy link
Author

now you need to pass this list to recylerview adapter and show in the recylerview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment