फ्लो द्वारा लिखे गए ट्यूटोरियल के कोड का उपयोग करके, मैंने स्ट्रिंग्स के दो अलग-अलग सेट दिखाने के लिए निम्न आइटमस्पिनर एडाप्टर बनाया, जब आइटम प्रदर्शित होते हैं, और एक नहीं। मुझे उम्मीद है कि यह किसी की मदद करेगा।
public class CustomSpinnerAdapter extends ArrayAdapter<String> {
Context mContext;
int mTextViewResourceId;
String[] mObjects;
String[] mShortNameObjects;
public CustomSpinnerAdapter(Context context, int textViewResourceId,
String[] objects, String[] shortNameObjects) {
super(context, textViewResourceId, objects);
mContext = context;
mTextViewResourceId = textViewResourceId;
mObjects = objects;
mShortNameObjects = shortNameObjects;
}
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
TextView row = (TextView) inflater.inflate(mTextViewResourceId, parent, false);
row.setText(mObjects[position]);
return row;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
public View getCustomView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
TextView row = (TextView) inflater.inflate(mTextViewResourceId, parent, false);
row.setText(mShortNameObjects[position]);
return row;
}
}
और उपयोग एक टुकड़ा अंदर:
CustomSpinnerAdapter mSpinnerAdapter = new CustomSpinnerAdapter(getActivity(), R.layout.spinner_item, getResources().getStringArray(R.array.action_filter), getResources().getStringArray(R.array.action_filter_short_names));
अंत में, स्पिनर आइटम के लिए लेआउट:
spinner_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18dip"
android:gravity="left"
android:textColor="@color/navdraw_list_item_background_default"
android:padding="5dip" />
कृपया मेरा जवाब http://stackoverflow.com/questions/4880413/text-color-of-a-closed-spinner/34264463#34264463 –
http://stackoverflow.com/questions/4880413/text- रंग-की-एक-आप बंद हो स्पिनर/34264463 # 34264463 –