如何自定义微调框

时间:2019-06-13 03:50:20

标签: android android-spinner

我想添加一个自定义微调框,方法。这是我的代码显示错误

 <Spinner
      android:id="@+id/homeBtnChooseCountry"
      style="@style/spinner_style"
      android:layout_width="146dp"
      android:layout_height="62dp"
      android:layout_alignParentEnd="true"
     android:layout_alignParentBottom="true"
      android:layout_marginEnd="20dp"
      android:layout_marginBottom="64dp"
      android:text="Choose Country" />

MainActivity.java

Spinner mySpinner = (Spinner)findViewById(R.id.homeBtnChooseCountry);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            R.layout.simple_list_item_1, R.id.homeCountryList);
    mySpinner.setAdapter(adapter);

}

还有这个

    private void chooseCountry() {   
    View view = initPopUp(R.layout.choose_country, 0.6f, 0.8f, 0.8f, 0.7f);

    final List<String> countryListName = new ArrayList<String>();
    for (Server server : countryList) {
        String localeCountryName = localeCountries.get(server.getCountryShort()) != null ?
                localeCountries.get(server.getCountryShort()) : server.getCountryLong();
        countryListName.add(localeCountryName);
    }

    ListView lvCountry = (ListView) view.findViewById(R.id.homeCountryList);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, countryListName);

    lvCountry.setAdapter(adapter);
    lvCountry.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            popupWindow.dismiss();
            onSelectCountry(countryList.get(position));
        }
    });

0 个答案:

没有答案