0

我正在开发一个应用程序,该应用程序在选项卡内有滑动选项卡,有按钮,例如 fragmenttab1 有 Algabra 按钮,当用户单击此按钮时,我想要它,它会将它们带到 AlgabraHome.class

AlgabraHome.class

package com.androidbegin.absviewpagertutorial;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.content.Intent;

import com.actionbarsherlock.app.SherlockFragment;



public class FragmentTab1 extends SherlockFragment {

    private Button btn;
    private Button btn2;
    private Button btn3;
    private Button btn4;
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Get the view from fragmenttab1.xml
        View view = inflater.inflate(R.layout.fragmenttab1, container, false);
        btn = (Button) view.findViewById(R.id.algabra);

        btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(FragmentTab1.this, AlgbraHome.class);
            startActivity(intent);

        }




        return view;
    }


    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        setUserVisibleHint(true);
    }

}

我不断收到流动错误:

Description Resource    Path    Location    Type
Syntax error, insert "}" to complete ClassBody  FragmentTab1.java   
/School Tools/src/com/androidbegin/absviewpagertutorial line 35 Java Problem
The constructor Intent(FragmentTab1, Class<AlgbraHome>) is undefined    FragmentTab1.java   
/School Tools/src/com/androidbegin/absviewpagertutorial line 32 Java Problem
Syntax error, insert ")" to complete MethodInvocation   FragmentTab1.java   /School Tools/src/com/androidbegin/absviewpagertutorial line 35 Java Problem

我试过用眼睛看它,但没有运气

如果可以的话请帮忙

提前感谢

问候 Rapsong11

4

2 回答 2

2

改变

Intent intent = new Intent(FragmentTab1.this, AlgbraHome.class);

Intent intent = new Intent(FragmentTab1.this.getActivity(), AlgbraHome.class);

于 2013-09-18T03:57:45.933 回答
0

Intent您似乎正在使用的构造函数是

public Intent(Context packageContext, Class<?> cls)

如javadoc中所见。

该类Fragment不是 的子类Context。如果 anActivity当前与 相关联Fragment,您可以调用getActivity()由 返回的引用(Fragment.this如果这是您的要求)。

于 2013-09-18T03:58:15.680 回答