为什么数据不会显示在android的活动中?

时间:2016-08-22 09:38:16

标签: android android-spinner baseadapter

在用户按下微调器之前,MaterialSpinner的数据不会显示。但是当用户按下微调器时,MaterialSpinner的日期会显示。选中后,它不会显示在MaterialSpinner中。

MainActivity.java

spn_menu = (MaterialSpinner) findViewById(R.id.spn_menu);       
spn_menu.setAdapter(new ItemSpinnerAdapter(this, foods));

ItemSpinnerAdapter.java

public class ItemSpinnerAdapter extends BaseAdapter {

    private Context context;
    private List<Food> food_list;

    public ItemSpinnerAdapter(Context context, List<Food> food_list) {
        this.context = context;
        this.food_list = food_list;
    }

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

    public Food getItem(int position) {
        return food_list.get(position);
    }

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

    public View getView(int position, View convertView, ViewGroup parent) {
        TextView tv = (TextView) convertView;
        if (tv == null) {
            tv = (TextView) LayoutInflater.from(context).inflate(R.layout.custom_spinner_item, parent, false);
        }
        tv.setText(getItem(position).getName());
        return tv;
    }
}

0 个答案:

没有答案