1
I’m having trouble fetching some data from a specific parameter, in my android app, in the webservice I already search and using GET with the data I want it brings me the data, but I need that when I insert a text into my edittext and press the button it only search for the data of the parameter I searched, someone could help me?
GET that specific search given by clicking the button.
@GET("Produto/get/CHICLETES")
Call<List<GitHubRepoBuscar>> reposForUser();
GET that is to bring the data written in edittext.
@GET("Produto/get/{busca}")
Call<List<GitHubRepoBuscar>> reposForUser(
@Path("busca") String busca
);
Main2activity class:
public class Main2Activity extends AppCompatActivity {
private ListView listView;
private EditText editText;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
editText = (EditText) findViewById(R.id.editTextBuscar);
listView = (ListView) findViewById(R.id.listView2);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(),"Buscando: " + editText.getText().toString(), Toast.LENGTH_SHORT).show();
loadJson();
}
});
}
public void loadJson(){
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("http://192.168.25.237:8080/FazendaWebservice/webresources/fazenda/")
.addConverterFactory(GsonConverterFactory.create());
Retrofit retrofit = builder.build();
GitHubClientBuscar client = retrofit.create(GitHubClientBuscar.class);
Call<List<GitHubRepoBuscar>> call = client.reposForUser("descricaocompleta");
call.enqueue(new Callback<List<GitHubRepoBuscar>>() {
@Override
public void onResponse(Call<List<GitHubRepoBuscar>> call, Response<List<GitHubRepoBuscar>> response) {
List<GitHubRepoBuscar> repos = response.body();
listView.setAdapter(new GitHubRepoBuscarAdapter(Main2Activity.this, repos));
}
@Override
public void onFailure(Call<List<GitHubRepoBuscar>> call, Throwable t) {
Toast.makeText(Main2Activity.this, " Erro ao estabelecer conexão" +"\n"+"Por favor tente novamente mais tarde!", Toast.LENGTH_SHORT).show();
}
});
}
}
Thank you! It worked
– Renato Crispim