2013-06-04 2 views
4

У меня есть адаптер, который простирается от ArrayAdapter, чтобы заполнить один Spinner одной коллекцией объектов (Город). И все объекты и адаптер работают правильно, по крайней мере, то, что кажется. Проблема в том, что когда я показываю все коллекции городов, она отображается в UP вместо DOWN.Spinner 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);   
    } 

Мои 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> 

Моя активность

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 на счетчик. У спиннера недостаточно места для открытия вниз.

Смежные вопросы