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):コールバックの処理に失敗しました。インターフェイスが実装されていません、> callback:android.widget.AdapterView $ SelectionNotifier @ 40dc5598

何が悪いのかわかりません。誰か助けてくれませんか?ありがとう!

4

0 に答える 0