我有一个带有背景图像的微调器。但是当我向微调器添加数组适配器时,文本显示在背景图像上。我想隐藏这个文字。还有一个TextView。我的要求是,当我单击图像时,应该弹出微调器,当我选择一个项目时,TextView会使用所选项目进行更新。
答案 0 :(得分:10)
Spinner spin = (Spinner) d.findViewById(R.id.searchCriteria);
spin.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// hide selection text
((TextView)view).setText(null);
// if you want you can change background here
}
public void onNothingSelected(AdapterView<?> arg0) {}
});
答案 1 :(得分:1)
使用以下文本在layouts文件夹中创建ghost_text.xml:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/transparent" />
然后在您的适配器中使用该文件,如下所示:
ArrayAdapter<String> your_adapter = new ArrayAdapter<String>(this,
R.layout.ghost_text, your_list);
your_spinner.setAdapter(your_adapter);
您还应该能够将此技术用于其他基于资源的适配器。
答案 2 :(得分:0)
您可以定义一个xml-layout文件,其中没有任何textview,并将其提供给微调器的适配器。
e.g。 empty_spinner_item.xml
<ImageView xmlns:android="http..."
android:layout_width=".."
/>
然后使用任何适配器:
spinner.setAdapter(new SimpleAdapter(this, data, R.layout.empty_spinner_item, ... ));