1

Below is a custom activity I've created for android

public class DisplayMenusActivity extends Activity implements OnItemSelectedListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_menus);
    // Show the Up button in the action bar.
    getActionBar().setDisplayHomeAsUpEnabled(true);
    Spinner spinner = (Spinner) findViewById(R.id.hall_spinner);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.hall_array, android.R.layout.simple_spinner_item);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_display_menus, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // This ID represents the Home or Up button. In the case of this
        // activity, the Up button is shown. Use NavUtils to allow users
        // to navigate up one level in the application structure. For
        // more details, see the Navigation pattern on Android Design:
        //
        // http://developer.android.com/design/patterns/navigation.html#up-vs-back
        //
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

public void onItemSelected(AdapterView<?> parent, View view, 
        int pos, long id) {
    URL menu_url = null;
    try {
        menu_url = new URL("http://www.housing.illinois.edu/Current/Dining/Menus.aspx?RIndex="+pos);
    } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    BufferedReader reader = null;
    StringBuilder builder = new StringBuilder();
    try {
        reader = new BufferedReader(new InputStreamReader(menu_url.openStream(), "UTF-8"));
        for (String line; (line = reader.readLine()) != null;) {
            builder.append(line.trim());
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        if (reader != null) try { reader.close(); } catch (IOException logOrIgnore) {}
    }

    TextView menu = (TextView) findViewById(R.id.menu_text);
    menu.setText(Html.fromHtml(builder.toString()));
    Log.v("DisplayMenusActivity", "HTML HERE: "+Html.fromHtml(builder.toString()));
}

public void onNothingSelected(AdapterView<?> parent) {
    TextView menu = (TextView) findViewById(R.id.menu_text);
    menu.setText("Yo wassup");
    Log.v("DisplayMenusActivity", "YO WASSUP\n\n\n");

}

}

When I touch the spinner I get the following logcat error at the top of the stack:

12-03 18:53:29.577: E/Handler(3232): Failed to handle callback; interface not implemented, > callback:android.widget.AdapterView$SelectionNotifier@40dc5598

I have no idea what is wrong. Can anyone help me out please? Thanks!

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
bsm
  • 207
  • 1
  • 10
  • It should work properly. Try to add Log.e as a first line of method onItemSelected(). So you can get idea whether it goes inside it or not – MysticMagicϡ Dec 04 '12 at 04:28
  • I used Log to find out that the error is with the URL scraping code. Is there a correct way of doing this in Android? – bsm Dec 04 '12 at 21:03
  • Check this SO answer: http://stackoverflow.com/a/2075847/1777090 . That might help – MysticMagicϡ Dec 05 '12 at 04:05

0 Answers0