I have Spinner
with custom layout in Android Studio:
user can choose item with custom layout ( Image + text)
I need to view only text on spinner after selected
not full layout
NOT LIKE THIS:
My custom Adapter
:
public class ColorAdapter2 extends ArrayAdapter<colorItem> {
LayoutInflater inflater;
ArrayList< colorItem> items;
public ColorAdapter2(Context context, int textViewResourceId,
ArrayList< colorItem> objects , LayoutInflater inflater) {
super(context, textViewResourceId, objects);
this.inflater = inflater;
items = objects;
}
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
public View getCustomView(int position, View convertView, ViewGroup parent) {
View row = inflater.inflate(R.layout.color_item, parent, false);
TextView label = (TextView) row.findViewById(R.id.nameColor);
label.setText(items.get(position).getName());
ImageView icon = (ImageView) row.findViewById(R.id.iconColor);
icon.setImageResource(items.get(position).getImageId());
return row;
}
}
...and the row layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@drawable/edittext"
android:padding="10dp"
android:layout_margin="10dp">
<ImageView
android:id="@+id/iconColor"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="30dp"
android:src="@drawable/blue_image"/>
<TextView
android:id="@+id/nameColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>