2017-02-26 24 views
0

我有國家名稱和下面的微調我正在顯示國家spinner.旗我想顯示國旗根據微調選擇,而不是所有..我怎麼能顯示在gridView?如何在gridview中顯示微調器選擇?

這裏是我的代碼:

public class FanciersFragment extends Fragment { 

    private View rootView; 
    private Spinner spFindCountry; 
    private RecyclerView rvFanciers; 
    private ArrayList<CountryDetail> countryDetailArray; 
    private LinearLayout llContainer; 
    private String countryCode; 

    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 

     rootView = inflater.inflate(R.layout.fragment_fanciers, container, false); 

     iitializeView(); 

     return rootView; 
    } 

    private void iitializeView() { 

     spFindCountry = (Spinner) rootView.findViewById(R.id.sp_country_find); 
     rvFanciers = (RecyclerView) rootView.findViewById(R.id.rv_fanc_items); 
     llContainer = (LinearLayout) rootView.findViewById(R.id.ll_fanciers_container); 

     GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity() , 3); 
     rvFanciers.setHasFixedSize(true); 
     rvFanciers.setLayoutManager(gridLayoutManager); 

     getCounties(); 

    } 


    @Override 
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 
     super.onViewCreated(view, savedInstanceState); 

     getActivity().setTitle("FanciersResponse"); 
    } 

    private void getCounties() { 

     if(Utility.isNetworkConnected(getActivity())) { 

      final Call<Countries> resp = Utility.getApiService().getContries(); 

      resp.enqueue(new Callback<Countries>() { 
       @Override 
       public void onResponse(Call<Countries> call, Response<Countries> response) { 

        if (response.code() == 200) { 

         Countries countries = (Countries) response.body(); 

         if (countries != null) 
          if (countries.getStatus() != null) 
           if (countries.getStatus().equals("OK")) { 

            countryDetailArray = (ArrayList<CountryDetail>) countries.getCountryDetails(); 
            if(countryDetailArray != null) 
             populateCountrySpinner(countryDetailArray); 
             pupulateFanciers(); 

           } else { 

            Utility.ShowSnackBar(countries.getStatusMessage() , llContainer); 
           } 
        } else { 

         Utility.ShowSnackBar("Network Error" , llContainer); 
        } 
       } 

       @Override 
       public void onFailure(Call<Countries> call, Throwable t) { 

        Utility.ShowSnackBar("No Response" , llContainer); 

       } 
      }); 

     } 
     else { 
      Utility.ShowSnackBar(getResources().getString(R.string.no_internet), llContainer); 

     } 
    } 

    private void pupulateFanciers() { 

     Fanciers rcAdapter = new Fanciers(getActivity(), countryDetailArray , new Fanciers.OnItemClickListener() { 
      @Override 
      public void onItemClick(CountryDetail item) { 

       if(item != null){ 

        Bundle b = new Bundle(); 
        b.putSerializable(Constants.COUNTRY_DETAILS , item); 
        Intent intent = new Intent(getActivity() , CountryBaseFanciers.class); 
        intent.putExtra(Constants.BUNDLE , b); 
        startActivity(intent); 

       } 
      } 
     }); 
     rvFanciers.setAdapter(rcAdapter); 
    } 

    private void populateCountrySpinner(final ArrayList<CountryDetail> countryDetailList) { 

     ArrayList<String> countryList = new ArrayList<>(); 

     if(countryDetailList != null){ 


      for(CountryDetail countryDetail: countryDetailList){ 

       countryList.add(countryDetail.getCountryName()); 
      } 

     } 
     /*adapterCountry = new ArrayAdapter<String>(getActivity(), R.layout.spinner_layout, R.id.tv_country_name, countryList); 
     spCountry.setAdapter(adapterCountry);*/ 

     HintSpinner<String> hintSpinner = new HintSpinner<>(
       spFindCountry, 
       // Default layout - You don't need to pass in any layout id, just your hint text and 
       // your list data 
       new HintAdapter<>(getActivity(), getResources().getString(R.string.find_country), countryList), 
       new HintSpinner.Callback<String>() { 
        @Override 
        public void onItemSelected(int position, String itemAtPosition) { 
         // Here you handle the on item selected event (this skips the hint selected event) 

         countryCode = countryDetailList.get(position).getCountryCode(); 



        } 
       }); 
     hintSpinner.init(); 
    } 


} 

我得到的gridview的所有標誌,但我想對spinner..kindly幫助選擇

回答

0

而不是使用GridView,儘量延伸ArrayAdapter類使用圖像,將其設置爲ListView並根據國家/地區名稱實施過濾器。如果一次只顯示一個標誌,這應該沒問題。

+0

它已經沒有選擇地工作了... wht可以是其他選項 – user7316606

+0

你想顯示_one_國旗根據選擇在微調右? –

+0

yes..ccording spinner – user7316606

相關問題