public class SpinAdapter extends ArrayAdapter<String> {
public SpinAdapter(Context ctx, int txtViewResourceId,
String[] objects) {
super(ctx, txtViewResourceId, objects);
}
@Override
public View getView(int pos, View cnvtView, ViewGroup prnt) {
return getCustomView(pos, cnvtView, prnt);
}
public View getCustomView(int position, View convertView,
ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.custom_spinner, parent, false);
TextView label = (TextView) row.findViewById(R.id.textSpinner);
label.setText(countriesList[position]);
return row;
}
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.sample_custom_spinner, parent,
false);
TextView label = (TextView) row.findViewById(R.id.textSpinner);
label.setText(countriesList[position]);
return row;
}
}
then set this adapter to spinner..
public SpinAdapter(Context ctx, int txtViewResourceId,
String[] objects) {
super(ctx, txtViewResourceId, objects);
}
@Override
public View getView(int pos, View cnvtView, ViewGroup prnt) {
return getCustomView(pos, cnvtView, prnt);
}
public View getCustomView(int position, View convertView,
ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.custom_spinner, parent, false);
TextView label = (TextView) row.findViewById(R.id.textSpinner);
label.setText(countriesList[position]);
return row;
}
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.sample_custom_spinner, parent,
false);
TextView label = (TextView) row.findViewById(R.id.textSpinner);
label.setText(countriesList[position]);
return row;
}
}
then set this adapter to spinner..
No comments:
Post a Comment