I have a created a custom ArrayAdapter to hold a tuple. I use one of the items in the tuple as the text to be displayed on a spinner which I have placed on a page.
Here is the code for my ArrayAdapter:
public class SpinAdapter extends ArrayAdapter<ObjectsForSpinner> {
private ArrayList<ObjectsForSpinner> _values;
public ObjectsForSpinner getItem(int position)
{
return _values.get(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
TextView label = new TextView(context);
label.settextColor(Color.BLACK);
label.setBackgroundColor(Color.TRANSPARENT);
label.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
label.setText(_values.get(position).getSpinnerStr());
return label;
}
}
_values.get(position).getSpinnerStr() is where I return the text. The return type is String. The problem is the text is not displayed completely. When I return Sales Department it only shows Sales without Department.
I even tried label.setEllipsize(TruncateAt.END); but no luck yet. Would some one please tell me how to go around this problem.
I have faced this problem before. The problem is that the
TextViewinside your Spinner completely ignores the parts after the space character when theTextViewsize is smaller than the whole String. You could identify this by removing the space characters from yourStringand displaying it. It will show you the part of the text that could fit inside yourTextView. But the moment the spaces are back, they are all gone.