0

我有这个类来定义我的滑动菜单项,并且我想在单击其中一些时启动不同的意图(不是片段,而是活动)。

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) {
        }

    }

}

但在以下几行

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

我收到此错误:

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

我怎样才能从这里开始一个意图?

另外,我如何为项目使用选择器,这不是他们的位置,因为这让我很困惑,我想用他们的名字来选择他们?

4

3 回答 3

1

更改此行

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

进入

Intent signup = new Intent(getActivity(), MyProfile.class); 
    startActivity(signup);
于 2013-10-17T07:40:14.880 回答
1

请将此替换Intent signup = new Intent(this, MyProfile.class);Intent signup = new Intent(getActivity(), MyProfile.class);

对于第二个问题,

if((((TextView)v.findViewById(android.R.id.text1)).getText().toString()).equals("Profile"))
{
    //Do your task here
}
于 2013-10-17T07:40:40.807 回答
1

尝试替换这个:

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

到 :

 Intent signup = new Intent(getActivity(), MyProfile.class);
于 2013-10-17T07:41:14.133 回答