将片段转到Activity

时间:2017-05-29 17:00:46

标签: java android

我的活动与片段沟通有问题。我不知道如何沟通这个

public class MyDreamsFragment extends Fragment {

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_addream:
                // go to Add DreamActvity.class
                return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

2 个答案:

答案 0 :(得分:0)

Intent intent = new Intent(getActivity(),DreamActvity.class); 。getActivity()startActivity(意向);

答案 1 :(得分:0)

Intent intent = new Intent(getActivity(),NewActivity.class);
startActivity(intent);

您必须使用getActivity()

调用片段的活动

已有old question about it