1

下面是我为 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");

}

}

当我触摸微调器时,我在堆栈顶部收到以下 logcat 错误:

12-03 18:53:29.577: E/Handler(3232): 处理回调失败;接口未实现,>回调:android.widget.AdapterView$SelectionNotifier@40dc5598

我不知道出了什么问题。谁能帮帮我?谢谢!

4

0 回答 0