質問

public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.hello_world, menu);
    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.new_task:
    newTask(null);
    return true;
    default:
    return super.onOptionsItemSelected(item);
    }
}

public void newTask (View view) {whatever}

=====

How do I call newTask from the menu? Eclipse offered to add null argument.

役に立ちましたか?

解決

If your newTask method is designed to be called by an onClick handler from a layout then you can add a tag to the view and then call view.getTag() inside your method.

That is one way that you could have many views call the same onclick handler method but then do different things.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top