Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一對多的情況(One Activity post to 2 fragmnet) #1

Closed
Jakevin opened this issue Feb 4, 2015 · 2 comments
Closed

一對多的情況(One Activity post to 2 fragmnet) #1

Jakevin opened this issue Feb 4, 2015 · 2 comments

Comments

@Jakevin
Copy link

Jakevin commented Feb 4, 2015

問題 Q

//Activity has a Fragmnet
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    EventBus.getDefault().register(this);    
    EventBus.getDefault().post("Jay Music","ticket");
}

@Subcriber(tag = "ticket")
public void onEvent(String event) {
    Log.e("","I got " + event +"ticket")
}

在Activity是沒有問題的,可以看到Log
at Activity ,Log is showing

//Fragment
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        EventBus.getDefault().register(this);    
}

@Subcriber(tag = "ticket")
public void onEvent(String event) {
    Log.e("","I got " + event +"ticket")
}

但在Fragment上卻無法顯示Log
Bug at Fragment , I can't get Log

@Jakevin
Copy link
Author

Jakevin commented Feb 4, 2015

我的錯 My fault

下面Code是正常的 The code is work

//Fragmnet
ViewModel viewModel;
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    viewModel = new ViewModel(this);
}
//ViewModel
public ViewModel(Fragmnet frg){
    EventBus.getDefault().register(this);    
}

@Subcriber(tag = "ticket")
public void onEvent(String event) {
    Log.e("","I got " + event +"ticket")
}

@hehonghui
Copy link
Owner

没事,希望尽量给出意见。刚才发现一些问题,我刚才更新了一下代码,你也更新一下吧。thanks~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants