我在这里问了一个大约一个星期前的问题, 关于一个自定义的螺旋桨, 并被引导到这个指南上。 http://ap- solut.com/blog/2011/03/using- custom-layout- for-spinner- or-listview- entries- in-android/
我跟踪了它,我试过调整它 与我的代码工作 并拉出结果 从数据库 到旋转器,但它不断崩溃。
这是旋转器的代码。
public class EditTeam extends Activity {
private final List<SpinnerEntry> spinnerContent = new LinkedList<SpinnerEntry>();
private Spinner D1Spinner;
private final ETSpinnerAdapter D1Adapter = new ETSpinnerAdapter(spinnerContent, this);
DataBaseHelper myDbHelper = new DataBaseHelper(this);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.editteam);
myDbHelper = new DataBaseHelper(this);
myDbHelper.openDataBase();
fillSpinner();
时 时
private void fillSpinner() {
Cursor c = myDbHelper.FetchDrivers();
startManagingCursor(c);
// create an array to specify which fields we want to display
String[] from = new String[]{"FirstName", "LastName"时 时;
// create an array of the display item we want to bind our data to
int[] to = new int[]{android.R.id.text1时 时;
spinnerContent.add(new SpinnerEntry(1, null, "Test"));
//adapter.setDropDownViewResource( R.layout.spinner_entry_with_icon );
D1Spinner = (Spinner) findViewById(R.id.spr_Driver1);
D1Spinner.setAdapter((SpinnerAdapter) D1Adapter);
时 时
时 时
我使用目前尚未修改的接触示例中的两门课。
正如你可以看到的,我正试图手动在目前添加一个项目,但当你装载时它就崩溃了。
这似乎是一个突破点?
05-25 15:17:34.773: E/AndroidRuntime(241): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.f1manager.android/com.f1manager.android.EditTeam时 时: java.lang.ClassCastException: com.f1manager.android.ETSpinnerAdapter
任何想法都将是伟大的。
谢谢
ETSpinnerAdapter 代码( 与示例中的原代码未修改) :
public class ETSpinnerAdapter {
private final List<SpinnerEntry> content;
private final Activity activity;
public ETSpinnerAdapter(List<SpinnerEntry> content, Activity activity) {
super();
this.content = content;
this.activity = activity;
时 时
public int getCount() {
return content.size();
时 时
public SpinnerEntry getItem(int position) {
return content.get(position);
时 时
public long getItemId(int position) {
return position;
时 时
public View getView(int position, View convertView, ViewGroup parent) {
final LayoutInflater inflater = activity.getLayoutInflater();
final View spinnerEntry = inflater.inflate(
R.layout.spinner_entry_with_icon, null); // initialize the layout from xml
final TextView contactName = (TextView) spinnerEntry
.findViewById(R.id.spinnerEntryContactName);
final ImageView contactImage = (ImageView) spinnerEntry
.findViewById(R.id.spinnerEntryContactPhoto);
final SpinnerEntry currentEntry = content.get(position);
contactName.setText(currentEntry.getContactName());
//contactImage.setImageBitmap(currentEntry.getContactPhoto());
return spinnerEntry;
时 时
时 时