小编Mar*_*k D的帖子

操作栏向上导航 Activity 到 Fragment

我正在开发一个带有导航抽屉的应用程序。虽然我以前没有任何片段经验,但我可以成功实现导航抽屉。现在我的问题是,我想要一个操作栏后退按钮。我以前在活动中尝试过这个。但现在的问题是我有一个片段,里面有一个点击事件。当用户单击按钮时,它会转到一个包含列表视图的活动。现在我想使用操作栏向上按钮返回到上一个片段。我该怎么做?当我按下手机上的后退按钮时,它工作正常。

我已经在我的列表视图活动中实现了 onOptionsItemSelected,如下所示。当我按下操作栏向上按钮时,它会进入登录窗口。不是我想要它去的地方。

public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch (item.getItemId()) {
    // Respond to the action bar's Up/Home button
    case android.R.id.home:
        Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is NOT part of this app's task, so create a new task
            // when navigating up, with a synthesized back stack.
            TaskStackBuilder.create(this)
                    // Add all of this activity's parents to the back stack
                    .addNextIntentWithParentStack(upIntent)
                    // Navigate up to the closest parent
                    .startActivities();
        } …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-actionbar

5
推荐指数
1
解决办法
1万
查看次数

将事件方法传递给孙组件

我对React还是有点陌生​​,所以如果这是一个newb问题,请原谅我。

我有一个基本组件(页面),它使用状态来控制是否显示模式弹出窗口:

constructor(props) {
    super(props);

    this.state = {
        showModal : false,
        modalContent : 'Initial Modal Content'
    };

    this.showModal = this.showModal.bind(this);
    this.hideModal = this.hideModal.bind(this);
}

showModal(modalContent) {
    this.setState({
        showModal : true,
        modalContent : modalContent
    });
}

hideModal(e) {
    this.setState({showModal : false});
}
Run Code Online (Sandbox Code Playgroud)

我的问题是我希望孙子组件能够打开我的模态。

我知道我可以通过将状态传递给子组件然后再传递给孙组件来做到这一点: <PartnersTable showModal={this.showModal} partners={PARTNERS} />

对我来说,这似乎有些草率,但这也许只是React的方式。

有人可以让我知道我是否正确执行此操作,或者是否有更清洁的方法来执行此操作?

您可以在GitHub上查看我的完整应用程序:https : //github.com/CCChapel/Thy-Kingdom-Come/blob/master/react.js

谢谢!

-埃里克

reactjs

2
推荐指数
1
解决办法
1395
查看次数