【发布时间】:2011-06-10 03:28:00
【问题描述】:
我正在尝试使用自定义 Spinner / ArrayAdapter。以下是我的代码:
myspinner=(Spinner)findViewById(R.id.myspinner);
myadapter=new ArrayAdapter<String>(this,R.layout.mytextview,R.id.mytv,sample_data);
myadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
myspinner.setOnItemSelectedListener(this);
myspinner.setAdapter(myadapter);
以下是包含mytv的自定义布局mytextview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="@+id/mylayout" android:layout_width="match_parent" android:layout_height="wrap_content">
<View android:layout_width="match_parent" android:layout_height="15dip" android:id="@+id/myview1" android:background="@color/bordertop"></View>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="30dip" android:id="@+id/mytv"></TextView>
<View android:layout_width="match_parent" android:layout_height="15dip" android:id="@+id/myview2" android:background="@color/borderbottom"></View>
</LinearLayout>
当我按下微调器以弹出弹出窗口时,Android 崩溃。当我注释掉 setDropDownViewResource 方法时,来的逻辑工作得很好。我仍然不明白 setDropDownViewResource 实际设置的视图。谁能告诉我默认情况下它的样子。而且,如果想用自定义布局覆盖它 - 布局是否需要具有特定结构?
【问题讨论】: