Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom Spinner Crashing
    primarykey
    data
    text
    <p>I asked a question on here about a week or so ago about a custom spinner and got led to this guide. <a href="http://app-solut.com/blog/2011/03/using-custom-layouts-for-spinner-or-listview-entries-in-android/" rel="nofollow">http://app-solut.com/blog/2011/03/using-custom-layouts-for-spinner-or-listview-entries-in-android/</a></p> <p>I followed it and I've tried adapting it to work with my code and pull the results from a database onto the spinner but it keeps crashing.</p> <p>This is the code for the spinner.</p> <pre><code>public class EditTeam extends Activity { private final List&lt;SpinnerEntry&gt; spinnerContent = new LinkedList&lt;SpinnerEntry&gt;(); 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); } </code></pre> <p>}</p> <p>And I am using the two classes from that contacts example which are un-modified at the moment.</p> <p>As you can see I'm trying to just manually add one item at the moment but it just crashes when you load it.</p> <p>This seems to be the breaking point?</p> <blockquote> <p>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</p> </blockquote> <p>Any ideas would be great.</p> <p>Thanks.</p> <p>ETSpinnerAdapter Code (Unmodified from the original code in the example):</p> <pre><code>public class ETSpinnerAdapter { private final List&lt;SpinnerEntry&gt; content; private final Activity activity; public ETSpinnerAdapter(List&lt;SpinnerEntry&gt; 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; } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload