문제

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