android - Spinner dropUP 而不是 dropDOWN android

标签 android drop-down-menu spinner android-arrayadapter

我有一个从 ArrayAdapter 扩展的适配器,以便用一个对象集合(城市)填充一个 Spinner。 所有对象和适配器都可以正常工作,至少看起来是这样。 问题是当我显示所有城市集合时,它显示为向上而不是向下。

有人知道会发生什么吗?

这是我的适配器

public class AdapterSpinnerListCities extends ArrayAdapter<City> {

// My context
private Context context;
// Values for the spinner (City)
private List<City> listLocationsSpinner = UpdatedStatusApplication.getListLocations();
Typeface tf = null;

public AdapterSpinnerListCities (Context context, int textViewResourceId, List<City> listLocationsAPP) {
    super(context, textViewResourceId, listLocationsAPP);
    this.context = context;
    this.listLocationsSpinner = listLocationsAPP;
    tf = CustomFontsLoader.getTypeface(this.context,CustomFontsLoader.FONT_CHALKBOARD_1);   
}

public int getCount(){
   return listLocationsSpinner.size();
}

public City getItem(int position){
   return listLocationsSpinner.get(position);
}

public long getItemId(int position){
   return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {         
    
    LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View item = convertView;  
    
    item = inflater.inflate(R.layout.list_item_city, null);
    TextView tvCity = (TextView)item.findViewById(R.id.tv_item_city);
    tvCity.setText(listLocationsSpinner.get(position).getCityName().toUpperCase()); 
    tvCity.setTypeface(tf);   
        
    return(item);
}



// And here is when the "chooser" is popped up
// Normally is the same view, but you can customize it if you want
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {       
    
    LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View item = convertView;  
    
    if (listLocationsSpinner.get(position).getCitySubcity() == TagManager.TAG_IS_NOT_SUBCITY){
        item = inflater.inflate(R.layout.list_item_city, null);
        TextView tvCity = (TextView)item.findViewById(R.id.tv_item_city);
        tvCity.setText(listLocationsSpinner.get(position).getCityName().toUpperCase());             
        tvCity.setTypeface(tf);             
    }
    else{
        item = inflater.inflate(R.layout.list_item_subcity, null);
        TextView tvSubCity = (TextView)item.findViewById(R.id.tv_item_subcity);
        tvSubCity.setText(listLocationsSpinner.get(position).getCityName());    
        tvSubCity.setTypeface(tf);              
    }
    return(item);        
  }

布局中的我的 Spinner(它是一个 RelativeLayout)

<LinearLayout
    android:id="@+id/lyt_locationSpinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/LinearLayoutLogo"
    android:layout_below="@+id/lyt_drink_food_deals"
    android:orientation="horizontal"         
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="5dp"         
    >                
    <Spinner android:id="@+id/cmb_location"
        style="@style/style_btn_request"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"                     
        android:spinnerMode="dropdown"            
        />                   
</LinearLayout>

我的 Activity

   private Spinner mySpinner;
   private AdapterSpinnerListCities adapter;
   List<City> listDeployedLocations = new ArrayList<City>();

    .....
    .....

    adapter = new AdapterSpinnerListCities (this,  android.R.layout.simple_spinner_dropdown_item, listDeployedLocations);        
    mySpinner = (Spinner) findViewById(R.id.cmb_location);
    mySpinner.setAdapter(adapter); // Set the custom adapter to the spinner
    
    mySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected (AdapterView<?> parentView, View selectedItemView, int position, long id) {
            citySelected = listDeployedLocations.get(position);
            System.out.println("Spinner value...."+ citySelected.getCityID()+"-"+citySelected.getCityName());
        }

        @Override
        public void onNothingSelected(AdapterView<?> parentView) {
            // code here
        }


    });   

最佳答案

如果使微调器充气的元素靠近屏幕底部,就会发生这种情况。由于如果向下充气旋转器将没有足够的空间(或几乎没有足够的空间),因此它会向上充气。尝试将微调器放在布局中更高(垂直)的位置。

关于android - Spinner dropUP 而不是 dropDOWN android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16910565/

相关文章:

android - 限制Android中按钮的宽度

单个项目上的 Android StickyListHeaders

php - 将 MYSQL 数据插入与下拉菜单中的字段关联的数据库表

android - 如何根据 android spinners 从 sqlite db 中选择的项目显示两个日期之间的数据?

jquery - 自定义数字微调器 Bootstrap jQuery

java - 如何从安卓连接共享点?

java - Google ANR 崩溃报告,您能联系到用户吗?

php - 使用 HTML PHP MySQL 的下拉导航菜单

css - IE7 和下拉列表 - 添加某种边距

android - 微调器中的图像+ TextView +单选按钮