Skip to content

Instantly share code, notes, and snippets.

@nikunjparadva
Last active May 27, 2019 11:23
Show Gist options
  • Select an option

  • Save nikunjparadva/48b96d0aad034f2349c9c6af3783dc8e to your computer and use it in GitHub Desktop.

Select an option

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();
}
});
}
}
@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