我正在使用游标从数据库中检索值,并使用简单的适配器列表在微调器中显示它们!一切都很好,唯一令我担心的是我希望自定义微调器的下拉,我搜索了很多,但由于我使用的数据库值无法得到任何结果!如果我们可以自定义下拉列表,请告诉我。
先谢谢!!
答案 0 :(得分:0)
答案 1 :(得分:0)
也许这会对你有所帮助:
要点:
row.xml在每一行上设置布局(在这种情况下:每行一个图像和文本):
<?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>
答案 2 :(得分:0)
谢谢你的帮助!!有效。不仅在xml中将其设置为背景,我还应该在java代码中将其设置为setDropDownViewResource()。它的运行。