In my Android application, I am using spinner, and I have loaded data from the SQLite database into the spinner, and it\'s working properly. Here is the code for that.
I have done this as following.I have use getDropDownView() and getView() methods.
Use getDropDownView()
for opened Spinner.
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater vi = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.context_row_icon, null);
}
TextView mTitle = (TextView) view.findViewById(R.id.context_label);
ImageView flag = (ImageView) view.findViewById(R.id.context_icon);
mTitle.setText(values[position].getLabel(activity));
if (!((LabelItem) getItem(position)).isEnabled()) {
mTitle.setTextColor(activity.getResources().getColor(R.color.context_item_disabled));
} else {
mTitle.setTextColor(activity.getResources().getColor(R.color.context_item));
}
return view;
}
And Use getView()
for closed Spinner.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater vi = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.context_row_icon, null);
}
TextView mTitle = (TextView) view.findViewById(R.id.context_label);
ImageView flag = (ImageView) view.findViewById(R.id.context_icon);
mTitle.setText(values[position].getLabel(activity));
mTitle.setTextColor(activity.getResources().getColor(R.color.context_item_disabled));
return view;
}