我使用图标和文本的适配器创建了Spinner
。一切都正确显示,但有一个要求活动微调只应显示文本。图标只应出现在下拉列表中。 这可能实现吗?仅在自定义微调框的下拉菜单中显示图标
public class CustomAdapter extends BaseAdapter {
Context context;
int flags[];
String[] countryNames;
LayoutInflater inflter;
public CustomAdapter(Context applicationContext, int[] flags, String[] countryNames) {
this.context = applicationContext;
this.flags = flags;
this.countryNames = countryNames;
inflter = (LayoutInflater.from(applicationContext));
}
[id3844467|@Override]
public int getCount() {
return flags.length;
}
[id3844467|@Override]
public Object getItem(int i) {
return null;
}
[id3844467|@Override]
public long getItemId(int i) {
return 0;
}
[id3844467|@Override]
public View getView(int i, View view, ViewGroup viewGroup) {
view = inflter.inflate(R.layout.custom_spinner_items, null);
ImageView icon = (ImageView) view.findViewById(R.id.imageView);
TextView names = (TextView) view.findViewById(R.id.textView);
icon.setImageResource(flags[i]);
names.setText(countryNames[i]);
return view;
}
}
XML
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:id="@+id/imageView" android:layout_width="40dp" android:layout_height="40dp" android:padding="5dp" android:src="@drawable/ic_launcher" /> // for check that icon existing <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:padding="0dp" android:text="Demo" // for check that text existing android:textColor="#000" /> </LinearLayout>
返回null可以请你解释一下这个部分:“但有一个愿望,将活动微调显示的文字,图标才出现在下拉列表中”? – vlatkozelka
可以请你正确地解释你想要的或按照你的要求显示一个屏幕截图 –
我的意思是,该默认微调器有文本和箭头。我用图像和文本创建了适配器。但现在当我关闭下拉列表时,图像也会出现。即是否可以在微调器关闭时进行此操作 - 微调器图像未显示,但显示在下拉列表中。 – user8214682