点击1菜单项后,我在右侧给出溢出按钮,它应该进入该活动,但我无法跳过该活动

时间:2017-04-10 07:19:19

标签: java android

public class HomeActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.homeactivity);
        list(getIntent().getExtras().getString("JSON_Object"));

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.items, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        super.onOptionsItemSelected(item);

        switch(item.getItemId()){
            case R.id.changepwd:
     //                Intent myIntent = new Intent(HomeActivity.this, Change_Password_Activity.class);
     //                this.startActivity(myIntent);
                startActivity(new Intent("com.example.aishwarya.registerlogin.change_password_activity"));
            Toast.makeText(this, "You selected change pwd", Toast.LENGTH_SHORT).show();
                break;

            case R.id.setuname:
                Toast.makeText(getApplicationContext(), "You selected set username", Toast.LENGTH_SHORT).show();
                break;

            case R.id.setdp:
                Toast.makeText(getApplicationContext(), "You selected set profile picture", Toast.LENGTH_SHORT).show();
                break;

        }
        return true;

    }

2 个答案:

答案 0 :(得分:0)

您应该使用您评论过的代码:

Intent myIntent = new Intent(HomeActivity.this, Change_Password_Activity.class);
 startActivity(myIntent);

确保您要隐式化的活动的名称具有名称" Change_Password_Activity "

答案 1 :(得分:0)

试试这个:

@Override
    public boolean onOptionsItemSelected(MenuItem item) {

        int id = item.getItemId();

        switch(id){
            case R.id.changepwd:
     //                Intent myIntent = new Intent(HomeActivity.this, Change_Password_Activity.class);
     //                this.startActivity(myIntent);
                startActivity(new Intent("com.example.aishwarya.registerlogin.change_password_activity"));
            Toast.makeText(this, "You selected change pwd", Toast.LENGTH_SHORT).show();
                break;

            case R.id.setuname:
                Toast.makeText(getApplicationContext(), "You selected set username", Toast.LENGTH_SHORT).show();
                break;

            case R.id.setdp:
                Toast.makeText(getApplicationContext(), "You selected set profile picture", Toast.LENGTH_SHORT).show();
                break;

        }
        return true;

    }