English 中文(简体)
自定义 Spinner 崩溃
原标题:Custom Spinner Crashing

我在这里问了一个大约一个星期前的问题, 关于一个自定义的螺旋桨, 并被引导到这个指南上。 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;
时 时

时 时

问题回答

似乎你的ETSpinnerAdapter并不是一个SpinnerAdapter,因为你正在得到一个班级选手,除了in。也许你可以为ETSpinnerAdapter发布你的代码?





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签