2013-06-04 37 views
4

我有一個適配器,從ArrayAdapter擴展爲了填補一個對象(城市)的一個微調。 所有對象和適配器都能正常工作,至少它看起來是什麼。 問題是,當我顯示所有城市集合時,它顯示爲UP而不是DOWN。微調器dropUP而不是dropDOWN android

有誰知道會發生什麼?

這是我的適配器

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);   
    } 

我的微調在佈局(它是爲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> 

我的動態

private Spinner mySpinner; 
    private AdapterSpinnerListCities adapter; 
    ![enter image description here][1]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 
     } 


    }); 

回答

5

這會發生,如果該項目其膨脹微調器靠近屏幕的底部。由於如果向下膨脹,微調器將沒有足夠的空間(或者僅有足夠的空間),而是向上膨脹。嘗試將旋轉器設置得更高(垂直)在佈局中。

+1

關鍵問題是因爲有一個滾動*無論如何*你如何配置它下拉(只)。即在任何情況下它絕不應該掉下來* –

0

嘗試添加marginEnd到微調器。紡紗工沒有足夠的空間向下打開。