简体   繁体   中英

trying to start a new activity from my pop up menu

I am trying to load a new activity called Make_a_contact . The user should click on id_Admin on the pop up menu and it should load Make_a_contact .

The second menu item id_User loads the Toast part just fine.

In my build error I get:

Error:(22, 50) error: cannot find symbol variable Make_a_contact

Do you know what could be wrong?

Here's my code:

package com.example.chris.omgandroid;

import android.content.Context;
import android.content.Intent;
import android.view.MenuItem;
import android.widget.PopupMenu;
import android.widget.Toast;
import android.app.Activity;
/**
 * Created by Chris on 07/01/2016.
 */
public class PopUpMenuEventHandle extends Activity implements PopupMenu.OnMenuItemClickListener {
    Context context;
    public PopUpMenuEventHandle(Context context){
        this.context = context;
    }
    @Override
    public boolean onMenuItemClick(MenuItem item){

        if(item.getItemId()==R.id.id_Admin)
        {
            Intent intent = new Intent (context, Make_a_contact);
            startActivity(intent);
//            Toast.makeText(context, "LoginAdmin has loaded!", Toast.LENGTH_LONG).show();
//            return true;
        }

        else if(item.getItemId()==R.id.id_User){

            Toast.makeText(context, "LoginUser has loaded!", Toast.LENGTH_LONG).show();
            return true;
        }
        return false;
    }

}

The Intent expects the Class instance of your Activity, which you can access with the .class field:

Intent intent = new Intent(context, Make_a_contact.class);

Just providing the standalone class name Make_a_contact is invalid Java in this case.

Make_a_contact.class

应该这样

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM