Kaloyan Roussev
Kaloyan Roussev

Reputation: 14711

Starting an intent from a sliding menu item

I have this class that defines my sliding menu items and I want to start different intents (not fragments, but activities) when some of them has been clicked.

public class RggarbSlidingMenu extends SherlockListFragment{

    String[] list_contents = {
        "My Profile",
        "My Items",
        "Messages",
        "Notifications",
        "Items Feed",
        "People Feed",
        "Places Feed",
        "Privacy Policy",
        "Terms of Service",
        "Settings",
        "Log Out"
    };

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        return inflater.inflate(R.layout.list, container, false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState){
        super.onActivityCreated(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, list_contents));
    }
    @Override
    public void onListItemClick(ListView l, View v, int position, long id){

        if (position == 0) {
            Intent signup = new Intent(RggarbSlidingMenu.this, Signup.class); 
            startActivity(signup);
        } else if (position == 1) {
        } else if (position == 2) {
        } else if (position == 3) {
        } else if (position == 4) {
        }

    }

}

but on the following lines

if (position == 0) {
        Intent signup = new Intent(this, MyProfile.class); 
        startActivity(signup);

I get this error:

The constructor Intent(RggarbSlidingMenu, Class<Signup>) is undefined

How can I start an intent from here?

Also, how can I use a selector for items, that is not their position, because this confuses me, I would like to select them by their name instead?

Upvotes: 0

Views: 737

Answers (3)

SathishKumar
SathishKumar

Reputation: 1644

Please replace this Intent signup = new Intent(this, MyProfile.class); with Intent signup = new Intent(getActivity(), MyProfile.class);

For second question,

if((((TextView)v.findViewById(android.R.id.text1)).getText().toString()).equals("Profile"))
{
    //Do your task here
}

Upvotes: 1

marshallino16
marshallino16

Reputation: 2671

Try to replace this :

Intent signup = new Intent(this, MyProfile.class); 

To :

 Intent signup = new Intent(getActivity(), MyProfile.class);

Upvotes: 1

kalyan pvs
kalyan pvs

Reputation: 14590

Change this line

Intent signup = new Intent(this, MyProfile.class); 
    startActivity(signup);

into

Intent signup = new Intent(getActivity(), MyProfile.class); 
    startActivity(signup);

Upvotes: 1

Related Questions