Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top