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