问题描述:

Data of MaterialSpinner doesn't show before the user presses the spinner. But Date of MaterialSpinner shows while the user is pressing the spinner. After selected, it doesn't show in 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;

}

}

相关阅读:
Top