カーソルでデータベースから値を取得し、単純なアダプタリストを使用してスピナーに表示しています!! 大丈夫です。心配しているのは、スピナーのドロップダウンをカスタマイズしたい外観だけです。たくさん検索しましたが、データベース値を使用しているため、結果が得られませんでした。ドロップダウンをカスタマイズできるかどうか教えてください。
前もって感謝します!!
カーソルでデータベースから値を取得し、単純なアダプタリストを使用してスピナーに表示しています!! 大丈夫です。心配しているのは、スピナーのドロップダウンをカスタマイズしたい外観だけです。たくさん検索しましたが、データベース値を使用しているため、結果が得られませんでした。ドロップダウンをカスタマイズできるかどうか教えてください。
前もって感謝します!!
多分これはあなたを助けるでしょう:
概要:
row.xmlを使用して、各行にレイアウトを設定します(この場合:各行に1つの画像とテキスト):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"/>
<TextView
android:id="@+id/weekofday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/new_button"/>//background changing as per selector
</LinearLayout>
Javaコードサンプル
public class AndroidCustomSpinner extends Activity {
String[] DayOfWeek = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner mySpinner = (Spinner)findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.row, R.id.weekofday, DayOfWeek);
mySpinner.setAdapter(adapter);
}
}
Addind Selector to TextView android:bacground="@drawable/new_button" can achieve your background on the basis of selected or focused
res/drawable/new_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_pressed_yellow"
android:state_pressed="true" />
<item android:drawable="@drawable/button_focused_orange"
android:state_focused="true" />
<item android:drawable="@drawable/button_normal_green" />
</selector>
助けてくれてありがとう!機能した。xmlでバックグラウンドとして設定するだけでなく、JavaコードでsetDropDownViewResource()に設定する必要があります。そしてその実行。