Advertisement
Neyasbit

dialog

Apr 13th, 2019
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. public class FilterDialog extends DialogFragment {
  2.     private List<Countries> countriesList = new ArrayList<>();
  3.     private ApiService service;
  4.     private AutoCompleteTextView autoCompleteTextView;
  5.     private List<Countries.CountriesData> countriesData = new ArrayList<>();
  6.     private Countries data;
  7.     private AutoCompleteCountryAdapter adapter;
  8.     private Call<Countries> call;
  9.  
  10.     @Override
  11.     public void onCreate(@Nullable Bundle savedInstanceState) {
  12.         super.onCreate(savedInstanceState);
  13.  
  14.         service = RetrofitBuilder.createService(ApiService.class);
  15.  
  16.         getCountries();
  17.     }
  18.  
  19.     private void getCountries() {
  20.         call = service.getCountries();
  21.         call.enqueue(new Callback<Countries>() {
  22.             @Override
  23.             public void onResponse(Call<Countries> call, Response<Countries> response) {
  24.                 if (response.isSuccessful()) {
  25.                     data = response.body();
  26.                     countriesData.addAll(data.getCountriesData());
  27.                     adapter.setCountryListFull(countriesData);
  28.                 }
  29.             }
  30.  
  31.             @Override
  32.             public void onFailure(Call<Countries> call, Throwable t) {
  33.  
  34.             }
  35.         });
  36.     }
  37.  
  38.     @Nullable
  39.     @Override
  40.     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  41.         View view = inflater.inflate(R.layout.fragment_filter, container);
  42.         autoCompleteTextView = view.findViewById(R.id.actv_countries);
  43.         adapter = new AutoCompleteCountryAdapter(getContext() ,countriesData);
  44.         autoCompleteTextView.setAdapter(adapter);
  45.         return view;
  46.     }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement