2011-02-08 19 views
3

私は背景イメージを持つスピナーを持っています。しかし、アレイアダプターをスピナーに追加すると、テキストが背景イメージに表示されます。私はこのテキストを隠したい。 TextViewもあります。私の要件は、画像をクリックするとスピナーがポップアップし、アイテムを選択するとTextViewが選択されたアイテムで更新されます。Androidスピナーのテキストを隠す

+0

重複質問が、応答しない:http://stackoverflow.com/questions/4342273/how-do-i-hide-the-text-on-a-spinner –

+0

私は同じ問題を越えましたが、私は私の9パッチPNGが無効であることを発見したので、修正パッチ9とクリーニングビルドプロジェクトが私のために働いた。私たちがあなたに何かを提案しやすいようにコードを投稿してください。 – Hiral

+0

http://stackoverflow.com/questions/15479579/remove-text-from-spinner - あなたの解決策 – Iurii

答えて

0

XMLレイアウトファイルをテキストビューなしで定義し、それをスピナーのアダプタに供給することができます。

empty_spinner_item.xmlその後、

<ImageView xmlns:android="http..." 
    android:layout_width=".." 
/> 

および任意のアダプタを使用します。

spinner.setAdapter(new SimpleAdapter(this, data, R.layout.empty_spinner_item, ...)); 
+0

しかし、それは私を助けませんでした;( – indira

+0

Gimmeもっと詳しく – xandy

+0

私は背景イメージを持つスピナーを持っています。配列アダプターをスピナーに追加すると、テキストが背景画像に表示されます。このテキストを非表示にしたいのですが、TextViewもあります。私の必要条件は、画像をクリックするとスピナーがポップアップし、 – indira

1

このテキストをあなたのレイアウトフォルダに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); 

また、他のリソースベースのアダプタでもこの手法を使用することができます。

9
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) {} 
}); 
関連する問題