2013-11-26 26 views
3

我試圖將我的片段從經典實現切換到AndroidAnnotations。 當我使用@EFragment(R.layout.my_fragment)時,我得到一個空白的視圖。使用AndroidAnnotations在片段中注入視圖

@EFragment(R.layout.my_fragment) 
    public class MyFragment extends Fragment { 
} 

如果我再這樣下去它的確定:

public class MyFragment extends Fragment { 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View view = inflater.inflate(R.layout.my_fragment, container, false); 
     return view; 
    } 
} 

我缺少什麼?文檔說加下劃線時,我實例化的片段,如:

MyFragment fragment = new MyFragment_(); 

代替:

MyFragment fragment = new MyFragment(); 

但如我所料,這是隻給一個編譯錯誤。

+1

您是否檢查過文件「MyFragment_」已生成? –

回答

4

我發現這是非常簡單的問題:

加入AndroidAnnotations我的片段後,我只是忘了更新它的進口在我Activty。它需要從改變:

import com.project.ui.fragment.MyFragment; 

到:

import com.project.ui.fragment.MyFragment_; 

之後,下面的:

MyFragment fragment = new MyFragment_(); 

工作得更好,顯然。

+0

但片段沒有被注入,它被宣佈,我是對嗎? – Fred37b