Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 正在FrameLayout中启动活动_Android_Android Intent_Android Activity_Android Framelayout - Fatal编程技术网

Android 正在FrameLayout中启动活动

Android 正在FrameLayout中启动活动,android,android-intent,android-activity,android-framelayout,Android,Android Intent,Android Activity,Android Framelayout,我需要在用户单击在FrameLayout中呈现的按钮后启动一个新活动。它呈现了我希望用户单击的按钮,但是现在它当然什么都没有做 该类的代码如下所示,但我不能调用startActivityintent public class TopBarView extends FrameLayout { private ImageView mLogoImage; private Button mInfoButton; public TopBarView(Context contex

我需要在用户单击在FrameLayout中呈现的按钮后启动一个新活动。它呈现了我希望用户单击的按钮,但是现在它当然什么都没有做

该类的代码如下所示,但我不能调用startActivityintent

public class TopBarView extends FrameLayout {

    private ImageView mLogoImage;
    private Button mInfoButton;

    public TopBarView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public TopBarView(Context context) {
        super(context);
        init();
    }

    public TopBarView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.top_bar, null);

        mLogoImage = (ImageView) view.findViewById(R.id.imageLogo);
        mInfoButton = (Button) view.findViewById(R.id.infoButton);

        mInfoButton.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // We load & render the view for the information screen
//              Intent i = new Intent();
//              i.setClass(getContext(), MeerActivity.class);
//              startActivity(i);
            }
        });

        addView(view);
    }
}
提前多谢

变化:

public void onClick(View v) {
// We load & render the view for the information screen
//              Intent i = new Intent();
//              i.setClass(getContext(), MeerActivity.class);
//              startActivity(i);
}
致:

注意:最好通过您正在使用的活动分配onclicklistener,以便在您想要使用MeePractivity以外的其他对象作为目标时,TopBarView更易于重用。没有大的变化:

public void onClick(View v) {
// We load & render the view for the information screen
//              Intent i = new Intent();
//              i.setClass(getContext(), MeerActivity.class);
//              startActivity(i);
}
致:

注意:最好通过您正在使用的活动分配onclicklistener,以便在您想要使用MeePractivity以外的其他对象作为目标时,TopBarView更易于重用。没什么大不了的