0

这是我使用的继承 GenericActivity -> GraphGenericActivity -> NormalActivity

我有一个选项菜单,其中包含一个帮助按钮,该按钮显示当前选项的帮助视图,这工作正常,但是关闭按钮不起作用,@Click我对任何视图都不起作用,如果我注册了onClickListener 老式方式它仅适用于直接从“GenericActivity”扩展的活动

通用活动

@EActivity
@OptionsMenu(R.menu.menu_generic)
public abstract class GenericActivity extends Activity{
    public static final String TAG = "GenericActivity";

    protected Context context;
    protected LayoutInflater vi;
    protected View helpView;
    @ViewById
    protected RelativeLayout rootLayout;
    @ViewById
    protected Button closeHelpButton;

    protected abstract int getHelpLayoutInt();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = this;
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }

    @AfterViews
    protected void afterViews() {
        vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        helpView = vi.inflate(this.getHelpLayoutInt(), null);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        helpView.setVisibility(View.GONE);
        if (helpView != null) {
            rootLayout.addView(helpView, layoutParams);
        }

        final Button button = (Button) findViewById(R.id.closeHelpButton);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            @Trace
            public void onClick(View v) {
                Toast.makeText(context, "close help", Toast.LENGTH_SHORT).show();
                if (helpView != null) {
                    helpView.setVisibility(View.GONE);
                }
            }
        });
    }


    @OptionsItem
    protected boolean menuHelp() {
        if (helpView != null) {
            if (helpView.getVisibility() == View.GONE) {
                helpView.setVisibility(View.VISIBLE);
            } else {
                helpView.setVisibility(View.GONE);
            }
        }
        return true;
    }


}

儿童活动

@EActivity(R.layout.activity_start_screen)
public class StartScreen extends GenericActivity {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getActionBar().setDisplayHomeAsUpEnabled(false);
        CALog.i("onCreateFinished");
    }


    @Trace
    @Override
    protected void onDestroy() {
        domboxTouchServiceManager.unbindFromDomboxService();
        super.onDestroy();
    }

    @Override
    protected int getHelpLayoutInt() {
        return R.layout.layout_start_screen_help;
    }

}
4

0 回答 0