Skip to content

Instantly share code, notes, and snippets.

@samuelloza
Created December 4, 2016 22:08
Show Gist options
  • Save samuelloza/a87d78c57ff6e5467ef500a47ee2c88e to your computer and use it in GitHub Desktop.
Save samuelloza/a87d78c57ff6e5467ef500a47ee2c88e to your computer and use it in GitHub Desktop.
package com.example.aliso.sd.activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;
import android.view.Menu;
import android.view.MenuItem;
import com.example.aliso.sd.R;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class MainActivity extends AppCompatActivity implements Callback<ResponsePost> {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(getApplicationContext(), "Da", Toast.LENGTH_LONG).show();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(NetworkInterfaces.URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
//RequestPost requestPost = new RequestPost("8448507");
NetworkInterfaces interfaces = retrofit.create(NetworkInterfaces.class);
Call<ResponsePost> responseCall = interfaces.hacerLlamada();
responseCall.enqueue(this);
Toast.makeText(getApplicationContext(), "FIN DA ", Toast.LENGTH_LONG).show();
}
@Override
public void onResponse(Call<ResponsePost> call, Response<ResponsePost> response)
{
ResponsePost responsePost = response.body();
System.out.println(" " + responsePost.getCorreo()+ " ");
Toast.makeText(getApplicationContext(),responsePost.getCelular() , Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(Call<ResponsePost> call, Throwable t)
{
int x = 0;
x++;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onStart() {
super.onStart();
}
@Override
public void onStop() {
super.onStop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment